PHP echo with commas versus concatenation

"echo" and "print" are used in PHP for writing strings out to a stream. I have always used concatenation when writing out multiple strings with echo or print, but recently discovered that echo accepts multiple arguments or parameters, comma separated like a regular function call. This post does some benchmarking to see which is faster: echo with commas, echo with concatenation, or print with concatenation.

Categories PHP

Displaying PHP APC Cache Information

APC is the Alternative PHP Cache, which is a free, open, and robust framework for caching and optimizing PHP intermediate code. I posted about how to install APC on Linux a couple of days ago, and will now look at the apc.php script which comes with APC and shows information about how much of the cache is being used, what files are being cached, the number of times they’ve been accessed etc.

Categories PHP

PHP Error Class ‘SoapClient’ not found

I’ve often found that something gets left out or forgotten when moving a website from an old server to a new install. I’ve just finished migrating one of my customer’s sites to a new CentOS 5.0 install with Apache 2.2 and PHP 5.1.6, and there’s one single PHP script in the site which uses the SoapClient class.

Naturally I’d forgotten to test this particular function until after the migration was complete, and was wondering why the script had failed. A quick look in the Apache error log file revealed the following error message: PHP Fatal error: "Class ‘SoapClient’ not found"

PHP Error Class ‘XsltProcessor’ not found

If you get the following error message in PHP then it means you need to have the XSL extension installed. Obviously the /path/to/file.php will be the actual path and filename of the PHP script the error occured in, and the line number will be the actual line. The PHP manual says that "PHP 5 includes the XSL extension by default" but one of my CentOS 5 installations it didn’t seem to be; the following post looks at how to install this extension on CentOS 5.

Fatal error: Class 'XsltProcessor' not found in /path/to/file.php on line 138
Categories PHP

Javascript and CSS file timestamps with PHP

Many websites I have worked on have frequently modified CSS style sheets and Javascript library files. In order to prevent Javascript errors or layout and style issues caused by web browsers caching these files, I used to rename the file for each revision, and then modify the name of the CSS or JS file in my PHP header include files. This article looks out how I now do this using the modified timestamp of the file.

Create a file with a unique name with PHP

The PHP function tempnam() creates a file with a unique name. This can be useful if you need to output some data into a temporary file for one reason or another, and the actual name of the file is not important.

Categories PHP