Splitting a large Apache log file with PHP

A little while back I needed to split a large Apache log file (3.5GB) up into smaller pieces and wanted to break it up into several files, with one for each day of the month. I initially tried using "grep" on the command line but this proved to be too slow, and I needed to run it once for each day and month so it was going to take 92 times to run, extracting just one day at a time over the course of three months. I ended up writing a quick little PHP script which was able to split the 3.5GB file into 92 files, one for each day of each month in under 4 minutes.

 

Categories PHP

Errors Compiling PHP with Sablotron

When compiling PHP with Sablotron there are errors which prevent PHP from compiling. This article covers what you need to do to enable PHP to compile correctly with Sabloton.

Categories PHP

PHP error Call to undefined function ImageCreateFromPNG

If you get the following error message in PHP then it means you need to have the PHP GD 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.

Fatal error: Call to undefined function ImageCreateFromPNG() 
  in /path/to/file.php on line 379

You’ll also get this error message using other functions such as ImageCreateFromJPEG() if the PHP GD library is not installed.

Categories PHP

Process Forking with PHP

This article covers howto fork a child process using the PHP command line client and PHP process control functions. Several examples illustrate how to create child processes and make the parent wait until they have finished before continuing processing.

Categories PHP

Install APC for PHP on Linux

APC is the Alternative PHP Cache, which is a free, open, and robust framework for caching and optimizing PHP intermediate code. What this means is that APC reads your PHP files, parses them into a more efficient binary format and then caches them in memory so that each request for your PHP files and PHP library files can be fed from the parsed cache. This will generally lead to a speed increase when serving a PHP site, especially one with a lot of library files. This post looks at how to install APC for PHP on Linux. The Linux distribution I used was CentOS 5, but it should be fairly similar for most distros.

Categories PHP

Correcting the PHP timezone

The end of daylight savings in New Zealand has been changed from Sunday March 16th (today) to Sunday April 6th. Last week I looked out how to check the daylight savings dates will be applied correctly on Linux, but now that it’s actually the day itself it turns out that while the operating system is using the correct date, PHP is not due to PHP5 maintainin its own internal timezone database. This post looks at how to temporarily correct the solution until it’s fixed in the distro’s PHP builds.

Categories PHP