Windows机器上的PHP;在后台启动进程

2022-01-08 00:00:00 windows background kill nohup php

我正在寻找最好的方法,或者任何真正在后台从 php 启动进程的方法,以便稍后在脚本中终止它.

I'm looking for the best, or any way really to start a process from php in the background so I can kill it later in the script.

现在,我正在使用:shell_exec($Command);这样做的问题是它等待程序关闭.

Right now, I'm using: shell_exec($Command); The problem with this is it waits for the program to close.

我想要在执行 shell 命令时与 nohup 具有相同效果的东西.这将允许我在后台运行该进程,以便稍后在脚本中将其关闭.我需要关闭它,因为这个脚本会定期运行,运行时程序无法打开.

I want something that will have the same effect as nohup when I execute the shell command. This will allow me to run the process in the background, so that later in the script it can be closed. I need to close it because this script will run on a regular basis and the program can't be open when this runs.

我曾想过生成一个 .bat 文件以在后台运行命令,但即便如此,我以后如何终止该进程?

I've thought of generating a .bat file to run the command in the background, but even then, how do I kill the process later?

我看到的linux代码是:

The code I've seen for linux is:

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

编辑:事实证明我不需要终止进程

EDIT: Turns out I don't need to kill the process

推荐答案

请问这个PHP 手册中的函数 帮助?

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");
}

相关文章