Wednesday, August 18, 2010

Cron Daemon Complains About PHP Warnings

A recent upgrade of php5-common brought with it an annoying side effect - the root account is being spammed with email messages from the Cron Daemon, every 30 minutes:
Date: Wed, 18 Aug 2010 20:09:01 +0300                                                                                                                                                             
From: Cron Daemon                                                                                                                                                        
To: root@machine-cycle.home                                                                                                                                                                       
Subject: Cron    [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -type f -cmin +$(/usr/lib/php5/maxlifetime) -print0 | xargs -n 200 -r -0 rm  
                                                                                                                                                                                                  
PHP Warning:  Directive 'register_long_arrays' is deprecated in PHP 5.3 and greater in Unknown on line 0                                                                                          
PHP Warning:  Directive 'magic_quotes_gpc' is deprecated in PHP 5.3 and greater in Unknown on line 0                                                                                              
First, I had to determine the package causing the trouble:
# dpkg -S /usr/lib/php5/maxlifetime
php5-common: /usr/lib/php5/maxlifetime
While some of the bugs listed at the Debian BTS seemed relevant, none seemed to match my exact situation.

I searched for the exact error messages I got, and found a few references on the PHP BTS. Some of these revolved around a problem with disabling warning reports from the PHP interpreter.

I decided it was time to follow the code instead of hyperlinks.

The file /usr/lib/php5/maxlifetime is a short shell script which calls the PHP command line interpreter, like this:
php5 -c /etc/php5/apache2/php.ini -r 'print ini_get("session.gc_maxlifetime");'
I tried it at the command line, and I got the same warnings. Got it!

But now what? after all, I know next to nothing about PHP...

Well, it did seem plausible that the problem had to do with the configuration file /etc/php5/apache2/php.ini, so I stared at it for a while until I found that warning messages can be disabled like this:
error_reporting  =  E_ALL & ~E_NOTICE & ~E_WARNING
I got rid of the annoying email messages alright, but I didn't really solve the problem - it's just a workaround.

Life's full of workarounds, and I'm slowly getting used to it.