19Mar/101
Increasing the PHP CLI Memory Limit
I recently ran into an issue where a client's cron job refused to run because of fatal errors and running out of memory. The default php.ini allowed up to 128M, but the CLI just wouldn't accept that.
It turns out that there is an easy solution:
Old Cron Task:
php -q /home/user/path/to/cron.php
New Cron Task:
php -qn -d memory_limit=128M /home/user/path/to/cron.php
- The -q parameter was already present, and just tells the CLI not to print HTTP headers.
- -d allows you to overwrite or define php.ini directives. In this case, I told it to allow a memory_limit of 128M
- -n was the real life saver here. I first tried running the command without it and it still failed. On a long shot, I tried including the -n and suddenly it worked and the new memory_limit from the CLI was used.
So if you ever find yourself wondering why the PHP CLI won't accept your -d parameters, try using -n.
PS: Don't forget to check try php --help for other useful parameters and options.
December 13th, 2010 - 07:39
Thanks for the hint, you saved my day