我正在寻找最好的,或者任何真正的方法来从后台的php启动一个进程,这样我可以在稍后的脚本中杀死它。
现在,我正在使用:shell_exec($command);
问题是它等待程序关闭。
我希望在执行shell命令时能有与nohup相同的效果。这将允许我在后台运行进程,以便稍后在脚本中关闭它。我需要关闭它,因为此脚本将定期运行,运行时程序无法打开。
我曾想过生成一个.bat文件来在后台运行该命令,但即便如此,以后如何终止该进程?
我在Linux上看到的代码是:

$PID = shell_exec("nohup $Command > /dev/null & echo $!");
// Later on to kill it
exec("kill -KILL $PID");

编辑:原来我不需要终止这个过程

最佳答案

这有帮助吗?

function runAsynchronously($path,$arguments) {
    $WshShell = new COM("WScript.Shell");
    $oShellLink = $WshShell->CreateShortcut("temp.lnk");
    $oShellLink->TargetPath = $path;
    $oShellLink->Arguments = $arguments;
    $oShellLink->WorkingDirectory = dirname($path);
    $oShellLink->WindowStyle = 1;
    $oShellLink->Save();
    $oExec = $WshShell->Run("temp.lnk", 7, false);
    unset($WshShell,$oShellLink,$oExec);
    unlink("temp.lnk");
}

07-24 09:20