shell_exec 不执行浏览器请求

Ere*_*ara 2 php shell-exec

用户通过 POST 提交数据后,我显示一个临时页面并使用 shell_exec 在后台执行该过程,至少这就是我想要做的。

这是我的页面设置:

C:\larragon\www\index.php

<?php
    try {
        shell_exec("php " . __DIR__ . "/test.php");
    } catch(Exception $e) {
        echo "Exception: " . $e;
    }
?>
Run Code Online (Sandbox Code Playgroud)

C:\larragon\www\test.php

<?php
    $myfile = fopen(__DIR__ . "/testfile.txt", "w");
    echo "test";
?>
Run Code Online (Sandbox Code Playgroud)

如果我转到 localhost 或 localhost/index.php,第二个脚本不会运行。但是,当我尝试从 cmd 调用这两个脚本时,它们都适用。

php C:\laragon\www\index.php

php C:\laragon\www\test.php
Run Code Online (Sandbox Code Playgroud)

他们都工作并创建一个名为 testfile.txt 的文件

Abr*_*ver 5

您的网络服务器作为特定用户运行,并且需要路径,php.exe因为网络服务器用户没有路径环境变量:

shell_exec("c:\path\to\php " . __DIR__ . "/test.php");
Run Code Online (Sandbox Code Playgroud)