Archive for August, 2007

Web design portfolio - 595Chapter 32DebuggingThen, once you have chosen the function

Friday, August 31st, 2007

595Chapter 32DebuggingThen, once you have chosen the function you want, you might go into the parentheses to theright of the function name and start to insert the name of a variable by typing $. Again, ZendDevelopment Environment presents you with a list of available variables (it s very clever andtakes scope into account) and allows you to choose from the list with your mouse. Again, anopportunity for a silly typing error to cause a bug is eliminated. Finding errors when they occurThe value of a visual debugger can really become obvious when it s time to work through aprogram line-by-line to see where problems are appearing and what can be done about them. While, as discussed earlier in this chapter, it s possible to monitor programs to a certainextent by outfitting them with extra echoand print_r()statements that help you tracewhat s happening, that can be a laborious process and is suitable only for quick diagnoses oroccasional troubleshooting work. The tools in Zend Studio are vastly more useful and will payfor themselves quickly if you do a lot of debugging work. Stepping through programsZend comprises a client element and a server element. When installed together in a develop- ment environment, they can share information back and forth. One key advantage of this: The client (under the control of the programmer) can halt execution, or see the progress ofexecution line by line. Moving at such a deliberate pace, you can get a better idea of what s going on, particularlywhen you can monitor variable values at the same time. Monitoring variable valuesZend Studio provides programmers with a window into all their programs variables thosedeclared internally, by the program itself, and those available from outside (the $_POSTarray, for example). Figure 32-4 shows the Variables pane (in the lower-right corner of the application) displayingsome environment variables contained in the superglobal $_ENVarray. Using breakpointsWhen you re working with a long program, you don t always want to step through the wholething one line at a time. Instead, you might choose to establish a breakpoint. The debuggerwill execute normally up to the breakpoint; then it will pause. While execution is paused at the breakpoint, you can examine variable values, or begin tostep through a critical portion of your program slowly. It s one more tool to make your debug- ging more efficient.
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.

Web server - 594Part IIIAdvanced Features and TechniquesFigure 32-3:The Zend IDEAvoiding

Thursday, August 30th, 2007

594Part IIIAdvanced Features and TechniquesFigure 32-3:The Zend IDEAvoiding errors in the first placeBecause they re designed for creating PHP software, full-featured IDEs tend to keep you frommaking certain kinds of errors in the first place. For example, because they offer syntax highlighting (which causes, say, function names to berendered in black, literal values to appear in green, and variable names to show up in maroon), IDEs make it easier to catch dumb typographical errors. If you see that a function s argument which is supposed to be a variable and therefore rendered in maroon is in fact black, youknow you ve mistyped the variable name (perhaps by forgetting the $character). You getused to the patterns of colors, and it s obvious when a mistake has caused a disturbance inthe pattern. In addition, IDEs often feature code completion. Code completion presents you with a list oflegal options perhaps function names, or names of already-declared variables that couldgo at the point at which you re typing. For example, Zend Development Environment will notice if you begin a new line of code withstr. It will show you a list of all functions that start that way str_pad(), str_repeat(), str_replace(), and so on and allow you to choose one by pointing and clicking with your mouse. This eliminates one possible source of errors, in that you can t misspell the function name.
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.

Apache web server - 593Chapter 32DebuggingIn that syntax, type has one of

Wednesday, August 29th, 2007

593Chapter 32DebuggingIn that syntax, type has one of four possible values: 0: The message is handled according to the setting of error_login php.ini. 1: The message is sent by SMTP electronic mail to the address specified by the destina- tion parameter. 2: The message is referred to a remote debugger. 3: The message is added to the end of the file specified by the destination parameter. The following code shows several possible uses for error_log(): In php.ini, error_logis normally not set to anything it s commented out by default. Ifyou want to use the 0option to do anything, you ll have to modify the error_logsetting tosomething like this: error_log = syslogwhich causes error_log()to be the equivalent of syslog(3)on Linux (and thus also thePHP syslog()function) and to write events to the Event Viewer under Microsoft Windows. Alternately, the error_logvalue can equal a filename: error_log = c:logsphp.logVisual Debugging ToolsIf you re going to be doing a lot of development work, you might consider buying a commer- cial integrated development environment (IDE) for PHP. Though these can cost a couple ofhundred U.S. dollars or more, they can earn their keep by saving you time and making possi- ble the more efficient creation of working software. This section focuses on a highly respected and widely used commercial IDE called ZendDevelopment Environment (yes, it s from the same Zend Technologies as puts out the ZendEngine that runs PHP). You can read its specifications (and download a free 21-day demon- stration version, if you register) at www.zend.com. Figure 32-3 shows the Zend IDE in use.
From our experience, we can recommend PHP5 Web Hosting services, if you need affordable webhost to host and run your web application.

592Part IIIAdvanced Features (Web hosts) and TechniquesIn Microsoft Windows, the

Wednesday, August 29th, 2007

592Part IIIAdvanced Features and TechniquesIn Microsoft Windows, the first three of those (LOG_DEBUGthrough LOG_NOTICE) are consid- ered informational; the fourth and fifth are considered warnings, and the final three are notedin the Event Viewer as Alerts. All of them are shown with a source value of c-client, whichcorresponds to an ancillary process of the Apache server. The Event Viewer shown in Figure 32-2 reflects the results of the preceding listing. Figure 32-2:Errors at various severity levelsLogging to a custom locationUnder Linux, you can use this procedure to write log messages to a file of your choosing. Modify your /etc/syslog.conffile to include this line: local0.debug /var/log/php.logThen restart the syslogdaemon: /etc/init.d/syslog restartWith that done, you can refer to LOG_LOCAL0as part of an openlog()call, as is done here: The LOG_PIDargument that supplements openlog()states that the process ID of the offend- ing thread should be recorded in the log file with the other details. Using error_log() You can use error_log()to send an error message almost anywhere , including to an elec- tronic mail address. It s an easy and convenient way to report on unexpected conditions thatcrop up in your PHP software, yet few developers bother to use it. The basic syntax for error_log()is this: error_log(message, type [,destination])
Please visit our professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.

591Chapter 32DebuggingSimply put, syslog()allows you to specify the (Professional web hosting)

Tuesday, August 28th, 2007

591Chapter 32DebuggingSimply put, syslog()allows you to specify the degree of severity associated with the eventto be logged and to specify a message describing it. Those values are then written out as anaid to diagnostics. This code illustrates all possible syslog()severity options: $value) { syslog($value, $exclamations[$key]); } ?> That code results in eight errors being written to the system log. In a Unix system, PHP syslog()is functionally the same as syslog(3) refer to its manpage (man 3 syslog) and on a Microsoft Windows system, PHP syslog()writes to theEvent Log (specifically, to its Application Log portion). The error-defining codes, in order of increasing severity, are: .LOG_DEBUG .LOG_INFO .LOG_NOTICE .LOG_WARNING .LOG_ERR .LOG_CRIT .LOG_ALERT .LOG_EMERG36
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

590Part IIIAdvanced Features and Techniques$returnValue = many ; echo (Linux web host)

Monday, August 27th, 2007

590Part IIIAdvanced Features and Techniques$returnValue = many ; echo
$returnValue = ; echo $returnValue; return innerFunction($returnValue); } echo

The time has come, the Walrus said, to talk of ; echo outerFunction() . . ; ?> Using print_r() The usual printing functions are handy, but more specialized ones can prove more useful fordebugging purposes. Chief among these is print_r(), an extraordinarily clever print statement that, among otherthings, will automatically render the contents of an array in a way that s comprehensible to ahuman reader. Recall that this code: $stateCaps = array( New South Wales => Sydney , Victoria => Melbourne , South Australia => Adelaide ); echo $stateCaps; will result in some pretty useless output. It will say simply: ArrayNot too handy. In contrast, the same array definition, followed by this line: Print_r($$stateCaps); results in much more useful output: Array ( [New South Wales] => [Sydney] [Victoria] => [Melbourne] [South Australia] => [Adelaide] ) It s immediately obvious to the person doing the debugging what the contents (keys and val- ues) of the array are. Using syslog() PHP provides a function, syslog(), with which you can write directly into the log of the oper- ating system running your PHP environment. It s a handy function, useful if you want to log allsystem problems to a standard location or if you want to alert a system administrator whomight not be directly involved in PHP development.
You want to have a cheap webhost for your apache application, then check apache web hosting services.

Web site templates - 589Chapter 32DebuggingThat setting specifies that all errors and

Monday, August 27th, 2007

589Chapter 32DebuggingThat setting specifies that all errors and warnings are to be reported (a fact denoted byE_ALL), and (&) that run-time notices are not to be reported (denoted by ~E_NOTICE the ~ indicates NOT). Other possible values are included and documented in the numerous com- ment lines of php.iniitself. The level of reporting defined by error_reportingaffects the behavior of error logging (as enabled by log_errors=On) and error reporting (as enabled by display_errors=On) or both simultaneously if both are enabled. Error-Reporting FunctionsPHP, benevolent language that it is, comes equipped with a variety of functions programmerscan use to help locate problems and generally report on aspects of their programs status. These range from ordinary output-generating statements print(), echoand the like used in contexts that reveal details of variable values, to specialized functions that write tooperating systems logging mechanisms. This section introduces some PHP functions you can use to spot problems and report onyour programs condition. Diagnostic print statementsThe simplest troubleshooting technique involves placing echo and print statements in yourcode at key locations, so that the output contains information about the progress of executionthrough various functions and the values of key variables at different points. This is sort of apoor man s debugger you can trace variables during execution and see if (and if so, when) they change to some unexpected value. Here s a simple program that uses echo statements for tracing purposes: In innerFunction() now… ; $returnValue = $value . things
; echo
$returnValue = ; echo $returnValue; return $returnValue; } function outerFunction() { echo
In outerFunction() now… ;
If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.

588Part IIIAdvanced Features and TechniquesIf (Affordable web hosting) you do not

Sunday, August 26th, 2007

588Part IIIAdvanced Features and TechniquesIf you do not want errors to be displayed (and you shouldn t want them displayed on anypublicly accessible machine), the line should read like this: display_errors=OffIf left on in a production server environment, error reporting can result in important detailsof your software being inadvertently displayed to users. For example, an unexpected conditioncould cause the name of a variable or a database table to appear in an unsecured browserwindow. An attacker could use this information to exploit the production server. Figure 32-1shows an error reported as part of the regular output to a browser window. Figure 32-1:Error reporting in browser outputError loggingSimilar in function to error reporting, error logging causes error events to be recorded to atext file, rather than to the screen. It s a more secure option, and because log files should bekept in a directory with limited access, it s the error-recording technique that s preferred forproduction HTTP servers. As is the case with error reporting, error logging is turned on and off in php.ini. To turn iton, use this option: log_errors=OnAlternately, use this: log_errors=OffBy default, error logging is disabled in php.ini. For more detail on error reporting and logging, see Chapter 31. Choosing which errors to report or logWhether you choose to use error reporting (on screen) or error logging (to a file), you can spec- ifywhich errors are considered serious enough to record. In php.ini, the error_reportingvalue defines your logging preference. By default, error_reportingis set like this: error_reporting=E_ALL & ~E_NOTICECross- Reference36
Please visit our professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.

587Chapter 32Debuggingand get 10 lines of Common Log (Database web hosting)

Saturday, August 25th, 2007

587Chapter 32Debuggingand get 10 lines of Common Log Format output (assuming 10 loggable events have takenplace). More usefully, though, you can use tailin its follow (–follow) mode. In follow mode, tailreturns the 10 newest lines of a specified file, then goes into an infinite loop in which it watchesfor changes in the file and displays them when they happen. It s a simple way to monitor logfiles, and lots of administrators dedicate several terminals to the purpose of running tail–fsessions on various log files. The syntax is simple: tail –follow=name –retry error.logThat results in a constantly updated display of the contents of error.log. By specifying –follow=nameand –retry, the command guarantees that tail watches the file itself, notthe file descriptor. IISThe Microsoft HTTP server handles logging differently. Rather than log to a file, IIS records its status and error-reporting information so that it is available for examination in the EventViewer, which is one of the Administrative Tools on a Windows 2000 or XP system. You ll find IIS errors in the System Log portion of the Event Viewer window, with a sourcename of W3SVC. Microsoft offers advice on troubleshooting IIS errors at http://msdn.microsoft.com/library/ default.asp?url=/library/en-us/iisref/htm/TroubleshootingCommonIISErrors.asp. PHP Error Reporting and LoggingPHP can itself be a tremendous help in spotting errors. Straight out of the box, PHP will reporterror messages with output right into the browser window, complete with line numbers. This is as far as most people get with PHP s debugging aids, but it s important to know aboutthe details of configuring error reporting behavior in order to get the most out of it. While PHP will show you the line number on which it has detected an error, you have to beaware that that is not always the line to which you should go in order to make a repair. A for- gotten close-quote or neglected semicolon sometimes is not picked up by the interpreter untilseveral lines later, so you should be prepared to go back a bit to look for syntax errors of thatkind. Error reportingWhen the PHP interpreter places an error message in a program s output (most often resultingin the error message being displayed in a browser window), it s engaging in error reporting. Error reporting is a useful diagnostic tool that s turned on be default, but which should bedisabled on any PHP interpreter associated with a production server. Error reporting is turned on and off in php.ini. The key value is display_errors. If youwant errors to be rendered as part of your output, this line should appear in php.ini: display_errors=On36
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

586Part IIIAdvanced Features and TechniquesThe (Web server on xp) Common Log FormatBy

Saturday, August 25th, 2007

586Part IIIAdvanced Features and TechniquesThe Common Log FormatBy default, entries in the Apache error.log file use the standardized Common Log Format. Entries in this format each correspond to a single instance of request/response activity(requests and responses are, after all, what HTTP servers handle). For example, one linemight correspond to a request for an HTML page (and its subsequent service by Apache). The next line might correspond to the (automatic) request for and service of a JPEG fileembedded in that HTML document. In any case, Common Log Format entries look like this (in a single line): 192.168.100.1 - david [10/Nov/2003:18:00:30 -1100] GET /index.html HTTP/1.0 200 6590The most important elements of that line are: .192.168.100.1: The IP address of the client making the HTTP request. .david: The username of the authenticated user making the request. .[10/Nov/2003:18:00:30 -1100]: The date, time, and UTC offset of the request. .GET: The nature of the HTTP request: GET or POST. .index.html: The requested file. .HTTP/1.0: Version of the HTTP protocol used for the request. .200: Response code describing the result of the request (more on this later in this section). .6590: The number of bytes served out in HTTP response corresponding to this request. You ll find a more complete treatment of Apache log files, including the more obscure elementsof the Common Log Format, at http://httpd.apache.org/docs/logs.html#errorlog. HTTP response codesThough there are many HTTP response codes (the most famous being the 404 Not Found error), they exhibit a pattern that aids rapid decoding. In a nutshell: .200-series codes indicate success. .300-series codes indicate a redirection. .400-series codes indicate a client-side error (like a request for a nonexistent document). .500-series codes indicate a server-side error. You ll find a full list of HTTP response codes at www.w3.org/Protocols/rfc2616/rfc2616- sec10.html. Monitoring Apache logs with tailUnder Unix (including Linux), you usually have access to the GNU text utility suite. When it stime to monitor log files, one of the most useful of these tools is tail. In its default behavior, tailwill return the last (that is, most recent) 10 lines of a specifiedfile. You can use it like this: tail access.log36
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.