Force reload of updated CSS and Javascript files with unique filenames

When a CSS or Javascript file is changed the visitor’s browser needs to get the latest copy of the file to reflect the changes, but it will have been cached and may cause rendering or functionality issues depending on the changes. To force reloading of the CSS and Javascript file the files should be renamed each time they are changed; this can be automated by using PHP to add the timestamp of the file into the filename.

Seg fault or similar nasty error detected in the parent process

One of the servers I manage runs CentOS 5.0 with Apache 2.2 and PHP 5.1.6, and uses PHP’s APC 3.0.14 (Alternative PHP Cache). We process the logs using AWStats every 15 minutes, and rotate the logs on a daily basis. However, after two or three days of working correctly, Apache would crash and we’d get the following in the log files: “seg fault or similar nasty error detected in the parent process”

After some amount of searching on the Internet, the only thing I could come up with was that there was a bug in the PCRE extension in older versions of PHP that would cause the same message to occur in the error logs. One of the posts indicated that this particular message is also a symptom for lots of other memory-type bugs in Apache, so I can only assume that it’s the use of APC which is causing the error.

The interesting thing is that if Apache is reloaded or reloaded with “graceful” a few minutes later, then there aren’t any segfaults. Again, I can only guess that the memory issue causing the segfault is due to issues with the memory caching over time.

The script that processes the logs with AWStats, and also rolls the logs on a daily basis is as follows:

#!/bin/bash
 
 if [ `date +%H%M` == 0600 ]
 then
 mydate=`date +%Y%m%d`
 cd /var/log/httpd
 mv mylog.log mylog.log.$mydate
 /sbin/service httpd reload
 /var/www/awstats/cgi-bin/awstats.pl -update 
 -config=myconfig -LogFile=mylog.log.$mydate > /dev/null
 bzip2 mylog.log.$mydate
 else
 /var/www/awstats/cgi-bin/awstats.pl -update 
 -config=myconfig > /dev/null
 fi

A quick summary of what this is: if it’s 6am in the morning, the current log file is renamed with the current day’s date (eg mylog.log.20070921), processed using AWStats, and then compressed with bzip2. At all other times during the day, just AWStats is called.

The error message that I got in the log files was as follows:

[Fri Sep 21 06:00:03 2007] [notice] SIGHUP received. ?Attempting to restart
 [Fri Sep 21 06:00:03 2007] [notice] seg fault or similar nasty error detected in the parent process

After the attempt to reload Apache and getting this error message, Apache failed to start up again. Calling “service httpd start” got it running again.

The solution I have found is to stop and start Apache. There may be some other way of sorting this memory issue with APC out but I was unable to find a solution for it. So the script now looks like this:

#!/bin/bash
 
 if [ `date +%H%M` == 0600 ]
 then
 mydate=`date +%Y%m%d`
 cd /var/log/httpd
 mv mylog.log mylog.log.$mydate
 /sbin/service httpd stop
 /sbin/service httpd start
 /var/www/awstats/cgi-bin/awstats.pl -update 
 -config=myconfig -LogFile=mylog.log.$mydate > /dev/null
 bzip2 mylog.log.$mydate
 else
 /var/www/awstats/cgi-bin/awstats.pl -update 
 -config=myconfig > /dev/null
 fi

Since changing it, I have had no further segfaulting issues.

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"

Installing AWStats on CentOS

AWStats provides a useful overview of website statistics from your Apache log files. There is no automatic way to install AWStats on CentOS using yum, so this article looks at how to install AWStats on CentOS. The instructions below should also work on other Linux distributions that do not have an automatic way of installing AWStats.