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.

6 comments:

  1. Better use:

    error_reporting = E_ALL & ~E_DEPRECATED

    ReplyDelete
  2. Turns out my config file was way behind the packaged one, and your suggestion is the default setting these days.

    Thanks!

    ReplyDelete
  3. if you modified php.ini to add session.gc_maxlifetime = something instead of the default value of 1440 you will receive this message. grep -R 'session.gc_maxlifetime' /etc/php5/ and correct all values. it's a script in etc cron.d which deletes old session files for php that is returning this error.

    ReplyDelete
    Replies
    1. the idea is not to disable warnings and errors but instead correct the problem :P

      Delete
    2. First off, thanks for pointing out the source of the problem. I would never have guessed.

      As for always trying to correct the problem instead of disabling warning, well, that's a fine approach and I'm all for it - heck, my blog is all about this. But:

      a) I never modified that parameter - all occurrences are set to the default value of 1440, and
      b) the warning is disabled in the default config file,

      The real problem, it seems, is that my config file was not upgraded automatically for some reason, and I'm too clueless to figure it out on my own ...

      Delete
  4. Yes, it usually is a good idea to fix the problem rather than patch it with error_reporting...and it's also good to know how error_reporting works in detail, something I just picked up today in order to get rid of a harmless warning that was on my company's site. This was a helpful reference:

    http://www.programmerinterview.com/index.php/php-questions/how-to-remove-warnings-in-php/

    ReplyDelete