Behavioural differences on the command line
suggest changeWhen running from the CLI, PHP exhibits some different behaviours than when run from a web server. These differences should be kept in mind, especially in the case where the same script might be run from both environments.
- No directory change When running a script from a web server, the current working directory is always that of the script itself. The code
require("./stuff.inc");assumes the file is in the same directory as the script. On the command line, the current working directory is the directory you’re in when you call the script. Scripts that are going to be called from the command line should always use absolute paths. (Note the magic constants__DIR__and__FILE__continue to work as expected, and return the location of the script.) - No output buffering The
php.inidirectivesoutput_bufferingandimplicit_flushdefault tofalseandtrue, respectively. Buffering is still available, but must be explicitly enabled, otherwise output will always be displayed in real time. - No time limit The
php.inidirectivemax_execution_timeis set to zero, so scripts will not time out by default. - No HTML errors In the event you have enabled the
php.inidirectivehtml_errors, it will be ignored on the command line. - Different
php.inican be loaded. When you are using php from cli it can use differentphp.inithan web server do. You can know what file is using by runningphp --ini.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents