在Windows IIS7上运行PHP exec命令

Ala*_*Tan 5 php iis shell exec

有从php代码运行exec()和shell_exec()的问题.我在Windows IIS7上运行PHP5.3.(花了几个小时才最终得到它......)

以下exec()代码有效:

$cmd='cmd.exe /c C:\\<path/to/php/directory/>\php.exe -v';
exec($cmd,$output,$err);
var_dump($output); //dump the output
echo $err; //show the error code, should give 0 for no errors
Run Code Online (Sandbox Code Playgroud)

注意我已确保: - IIS Internet用户具有PHP目录的完整读取+执行权限 - IIS Internet用户具有对php.exe的完全读取+执行权限 - IIS Internet用户具有完整的读取+执行权限到cmd.exe

如果要从后台进程php文件输出大量数据,请使用shell_exec(),请参阅下面的工作代码(至少在我的设置中):

$cmd='cmd.exe /c C:\\<path/to/php/directory/>\php.exe -f C:\\<path\to\your\>\cron.php';
echo shell_exec($cmd); //output the data
Run Code Online (Sandbox Code Playgroud)

请注意,如果它什么都不返回,则表示路径有问题.

请记住使用"\"(不带引号)来模拟/替换实际Windows路径中的单反斜杠"\".

确保您的后台进程文件即cron.php也具有IIS Internet用户的权限.玩得开心!