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.ini
directivesoutput_buffering
andimplicit_flush
default tofalse
andtrue
, respectively. Buffering is still available, but must be explicitly enabled, otherwise output will always be displayed in real time. - No time limit The
php.ini
directivemax_execution_time
is set to zero, so scripts will not time out by default. - No HTML errors In the event you have enabled the
php.ini
directivehtml_errors
, it will be ignored on the command line. - Different
php.ini
can be loaded. When you are using php from cli it can use differentphp.ini
than 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