PHP CLI

This is post is now quite old and the the information it contains may be out of date or innacurate.

If you find any errors or have any suggestions to update the information please let us know or create a pull request on GitHub

Running PHP on the command line, via cron etc there are a few common problems you can hit and from experience this my recommendations to avoid them.

It seems that (on CentOS at least) PHP does not display errors by default on the command line. You will want it to I assume so you can understand what has gone wrong with the cron task etc.

You can use php.ini files but its not always easy to know exactly which ini file is going to to be used. If certain settings are required, use the -d flag to set specific ini directives directly when you run PHP.

I have just had an issue where a script was running out of memory but no error message was displayed, despite the fact that display errors was turned on. However digging around showed that memory usage was hitting the limit and the script died silently. Increasing the memory limit fixed it.

Here is my standard PHP CLI runner:


/usr/bin/php -d display_errors -d memory_limit=512M /path/to/php/file.php


Tags: phplinuxcronshellCLIscripterrorsmemory limit