Ubuntu – PHP Cron – Max Allocation

cronmemory usagePHPUbuntu

I'm getting email errors from a cron, on Ubuntu, that lives at:

/etc/cron.d/php5

I didn't install that cron, so I'm guessing it is installed with PHP. Its contents are as follows:

# /etc/cron.d/php5: crontab fragment for php5
#  This purges session files older than X, where X is defined in seconds
#  as the largest value of session.gc_maxlifetime from all your php.ini
#  files, or 24 minutes if not defined.  See /usr/lib/php5/maxlifetime

# Look for and purge old sessions every 30 minutes
09,39 *     * * *     root   [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -cmin +\
$(/usr/lib/php5/maxlifetime) -delete

It seems to be the cron that kills old sessions.

It is however, sending me this email error:

To: root

Subject: Cron <root@mailserver> [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib/php5/maxlifetime) -delete (failed)

Message:
PHP Fatal error:  Allowed memory size of 262144 bytes exhausted (tried to allocate 523800 bytes) in Unknown on line 0
find: invalid argument `-delete' to `-cmin'

Does anyone know how to go about remedying this?

EDIT: I know that 262144 bytes is not very much, so perhaps I should just bump up the memory limit? I figure that is a workaround, but I was just curious as to why these errors suddenly started popping up. There are never actually any $_SESSIONs created on this server, it's only used to send email.

Best Answer

My issue was in the way the Apache2 version of my .ini file was configured. It was set to allow for 1024MB of memory, rather than the correct 1024M. Someone else must have been messing around in it, since I'm only using PHP on this server via CLI.