【发布时间】:2013-03-24 06:43:37
【问题描述】:
我遇到了 exec 和 shell_exec 的问题,我查看了这里的每个帖子,但似乎无法找到问题所在。我正在使用的代码:
chdir('/');
$handle = shell_exec("/usr/bin/php /home/donor/public_html/batch/testlaunch.php 2>&1");
echo $handle .":". gettype($handle) . "\n";
$read = fread($handle, 2096);
echo $read;
屏幕如下所示:
...
X-Powered-By: PHP/5.3.21 Content-type: text/html (repeated about 100 times)
X-Powered-By: PHP/5.3.21 Content-type: text/html
PHP Warning: shell_exec() [function.shell-exec]: Unable to execute '/usr/bin/php /home/donor/public_html/batch/testlaunch.php 2>&1' in /home/donor/public_html/batch/test.php on line 4 X-Powered-By: PHP/5.3.21 Content-type: text/html
Warning: shell_exec() [function.shell-exec]: Unable to execute '/usr/bin/php /home/donor/public_html/batch/testlaunch.php 2>&1' in /home/donor/public_html/batch/test.php on line 4
:boolean PHP Warning: fread() expects parameter 1 to be resource, boolean given in /home/donor/public_html/batch/test.php on line 6
Warning: fread() expects parameter 1 to be resource, boolean given in /home/donor/public_html/batch/test.php on line 6
:string PHP Warning: fread() expects parameter 1 to be resource, string given in /home/donor/public_html/batch/test.php on line 6 (repeated another 100ish times)
PHP 安全模式已关闭。文件所在文件夹的权限 .../batch/ 和 /usr/bin/php 都设置为 755。除 php 外,所有文件的用户都相同(php 文件用户为 root)。 php.ini 文件中没有禁用任何内容。在 CLI 中运行良好。 whoami 和 ls 等简单的命令可以正常工作。我觉得我错过了什么
编辑: 尝试了cpattersonv1所说的并得到了:
X-Powered-By: PHP/5.3.21 Content-type: text/html sh: fork: retry: Resource temporarily unavailable sh: fork: retry: Resource temporarily unavailable sh: fork: retry: Resource temporarily unavailable sh: fork: retry: Resource temporarily unavailable X-Powered-By: PHP/5.3.21 Content-type: text/html sh: fork: retry: Resource temporarily unavailable sh: fork: retry: Resource temporarily unavailable sh: fork: retry: Resource temporarily unavailable sh: fork: retry: Resource temporarily unavailable sh: fork: Resource temporarily unavailable X-Powered-By: PHP/5.3.21 Content-type: text/html 2540000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
编辑 2:有谁知道为什么它看起来像是多次尝试命令?
编辑 3:我将命令放在 .sh 文件中并尝试运行它。在 CLI 中工作,但在 php 中也不能工作
chdir('/');
$handle = exec(". /home/donor/public_html/batch/test.sh");
我得到相同的输出;
【问题讨论】:
-
var_dump($handle) 会得到什么
-
"X-Powered-By: PHP/5.3.21 Content-type: text/html string(641) "X-Powered-By: PHP/5.3.21 Content-type: text/html字符串(573)
标签: php shell permissions exec shell-exec