如何运行这个PHP命令?
我有无法运行的php代码如何运行这个PHP命令?,php,web,vps,Php,Web,Vps,我有无法运行的php代码 $add_file_location = dirname(__FILE__); $shell_cmd = "php {$add_file_location}/test2.php mytest > /dev/null &"; shell_exec($shell_cmd); 如何运行代码,使其能够在web主机或vps上运行test2.php文件。您不希望为此使用shell\u exec $file_loc = dirname(__FILE__); requi
$add_file_location = dirname(__FILE__);
$shell_cmd = "php {$add_file_location}/test2.php mytest > /dev/null &";
shell_exec($shell_cmd);
如何运行代码,使其能够在web主机或vps上运行test2.php文件。您不希望为此使用shell\u exec
$file_loc = dirname(__FILE__);
require($file_loc.'/test2.php');
应该做你想做的。为什么不能运行?您是否收到任何错误或消息?您的主机可能出于正当理由禁用了
shell_exec
功能;它列出了所有文件,这意味着shell_exec函数已启用好的,您是否收到任何错误?尝试删除命令的/dev/null
部分,并捕获shell\u exec的返回值,以便查看输出内容。您可能还需要将php
更改为php二进制文件的完整路径,例如/usr/bin/php
X-Powered-By:php/4.4.9 Content-type:text/html X-Powered-By:php/4.4.9 Content-type:text/html X-Powered-By:php/4.4.9 Content-type:text/html X-Powered-By:
我将其作为输出,在您执行任何其他操作之前,您需要升级(或要求您的主机升级)PHP。自2008年以来,4.4.9版一直不受支持,可能会充满安全漏洞。但我想运行test2。phprequire
在功能上并不等同于shell_exec
,它们做两件完全不同的事情。不过,require将强制执行外部php文件。True,但是,您不能像使用shell\u exec
那样将命令行参数传递给该文件(并且正如OP所希望的那样)。在某些情况下,这确实是有意义的,例如,由于每个脚本的内存限制,我过去被迫使用exec
来运行PHP脚本。