I’m running the PHP CLI through a NSTask in MacOS, but this question is more about the CLI itself.
I’m listening to the stderr pipe, but nothing is output there no matter what file I try to run:
- If the file type is not a plain text,
stdoutsets to?. - If the file is a php script with errors, the error messages are still printed to
stdout.
Is there a switch to the interpreter to handle errors through stderr? Do I have an option to detect errors other than parsing stdout?
The
display_errorsdirective (can be set everywhere) takes optionally the parameter “stderr” for it to report errors to stderr instead of stdout or completely disabled error output. Quoting from the PHP manual entry:Alternatively if you’re using the commandline interface and you want to output the errors your own you can re-use the command-line nput/output streams:
Here
STDERRis an already opened stream to stderr.Alternatively if you want to do it just for this script and not in CLI you can open a filed handler to
php://stderrand write the error messages there.