我遇到了 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");
我得到相同的输出;