PHP cli script does not output anything

我的未来我决定 提交于 2019-12-03 09:59:29

display_errors might be disabled before runtime. You can turn it on manually with the -d switch:

php -d display_errors=1 -f my_script.php myArguments

I came across the same issue, and no amount of coercing PHP to display_errors or checking for syntax with -l helped

I finally solved our problem, and perhaps you can find some help with this solution

Test your script without using your php.ini:

php -n test_script.php

This will help you hone in on the real cause - PHP configuration, someone else's script, or your script

In my case, it was a problem with someone else's script which was being added via the auto_prepend_file directive in the php.ini. (Or more specifically, several files and functions later as I drilled through all the code adding debug as I went - on a side note, you may find that using fwrite(STDOUT, "debug text\n"); invaluable when trying to debug this type of issue)

Someone had added a function that was getting run through the prepend file, but had used the @ symbol to suppress errors on a particular function call. (You might have a similar problem but not specifically related to the php.ini if you have any includes in your test script bringing in other code)

The function was failing and caused the silent death of PHP, nothing to do with my test script

You will find all sorts of warnings about how using the @ symbol causes the exact problem I had, and perhaps you're having, http://php.net/manual/en/language.operators.errorcontrol.php.

Reproduction of similar symptoms:

Take a fully functional PHP environment, and break your CLI output by adding this the top of your script @xxx_not_a_real_function_name_xxx();

So you may just have a problem with the php.ini, or you (or someone else) may have used @ not realising the serious (and frustrating and time consuming) consequences that it causes in debugging

I experienced PHP CLI failing silently on a good script because of a memory limit issue. Try with:

php -d memory_limit=512M script.php
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!