问题描述
所以我有一个使用以下命令执行的php脚本:
So I have a php script which I execute using the following command:
php -f my_script.php myArguments
该脚本受使用svn的版本控制.我刚刚对其进行了更新,将要运行的命令粘贴到终端中,然后执行了它.但是,没有输出.不是失败消息,不是打印任何内容,什么也不做.看来它永远不会开始.有点像以下内容:
The script is under version control using svn. I just updated it, pasted the command to run it into a terminal, and executed it. However, there is no output. Not a failure message, not it printing anything, nothing. It looks like it never starts. Kind of like the following:
me:/srv/scripts# php -f my_script.php myArguments
me:/srv/scripts#
其他脚本可以正常运行.
Other scripts will run just fine.
我很难提出一个SSCCE,因为我无法真正共享导致此问题的代码,而且我也无法有意地复制此行为.但是,我已经两次看到了这一点.如果我保存所做的更改,还原文件,然后将其粘贴回,则很有可能正常运行.
It is difficult for me to come up with an SSCCE, as I can't really share the code that is causing this, and I haven't been able to replicate this behavior intentionally. I have, however, seen this twice now. If I save my changes, revert the file, and paste them back in, there is a strong chance it will run just fine.
但是,我担心不知道是什么导致了这种奇怪的行为.是否存在空格字符或告诉PHP无法启动或输出任何内容的字符?
However, I am concerned by not knowing what is causing this odd behavior. Is there a whitespace character or something that tells PHP not to start, or output anything?
这是我看到这种行为后尝试过的方法:
Here is what I've tried after seeing this behavior:
-
修改脚本,使其很简单
echo 'hello'
在脚本的开头放置废话,所以它是不可解析的.
Putting nonsense at the beginning of the script, so it is unparseable.
从工作脚本中粘贴代码
沮丧地将我的头撞在墙上
Banging my head on a wall in frustration
在另一个终端/putty ssh连接中尝试.
Trying it in another terminal/putty ssh connection.
在这里变得很有趣:它实际上在另一个终端中正常工作.它按预期完成所有操作.
Here's where it gets interesting: It actually works in a different terminal. It does everything as expected.
那么,有谁知道这可能是什么原因,或者我应该尝试以确定问题的方式?
So does anyone have any ideas what might be causing this, or things I should try in order to determine the problem?
不同的终端"仍然是终端应用程序,只是一个新的应用程序.
The "different terminal" is still the terminal application, just a new one.
我具有执行该文件的足够权限,但是即使我没有执行该文件,它也应该吐出一条消息,说我没有.
I have sufficient permissions to execute the file, but even if I didn't, it should spit out a message saying I don't.
我有意引入了语法错误,希望我能使PHP吐出一个解析错误.仍然没有输出.
I intentionally introduced syntax errors in hopes that I would get PHP to spit out a parse error. There was still no output.
推荐答案
display_errors 可能在运行时之前被禁用.您可以使用 -d开关:
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
这篇关于PHP CLI脚本不输出任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!