New Perspectives On Web Design

(C. Jardin) #1
By Paul Tero CHAPTER 8

$ grep alert /var/www/vhosts/smashingmagazine.com/statistics/logs/error_log
[Thu May 06 11:04:00 2013] [alert] [client 81.106.118.59]...


PhP PaRSe anD RunTiMe eRRoRS
Many websites use the LAMP combination: Linux, Apache, MySQL and
PHP. A common reason for Web pages not showing up is that they contain
a PHP error. Fortunately, these are quite easy to discover and pinpoint.
There are two broad classes of PHP errors: parse errors and runtime
errors. Parse errors are syntax errors and include leaving off a semicolon
or forgetting the $ in front of a variable name. Runtime errors include
undefined functions or referencing objects which don’t exist.
Like .htaccess errors, parse errors will cause an HTML response code
500 for Internal Server Error, often with a completely blank HTML page.
Runtime errors will give a successful HTML response of 200 and will
show as much HTML as they have processed (and flushed) before the error
happened. You can use telnet or wget -S or curl -i to get only the headers
from a URL. So now, copy and paste your erroneous page into a command:


$ curl -i http://www.smashingmagazine.com/products/widget-3000/123
HTTP/1.0 500 Internal Server Error
Date: Sun, 12 May 2013 17:44:49 GMT
Server: Apache
Vary: Accept-Encoding
Content-Length: 0
Connection: close
Content-Type: text/html


PhP eRRoR SeTTingS
To find the exact error, you need to make sure errors are being reported in
the log file.
There are several PHP settings which cover errors. display_errors
determines if errors are shown to the website visitor or not, and
log_errors says whether they will appear in log files. error_reporting
specifies the types of errors that are reported: only fatal errors, for example,

Free download pdf