PHP在Windows机器上;启动后台进程 [英] PHP on a windows machine; Start process in background

查看:313
本文介绍了PHP在Windows机器上;启动后台进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找最好的,或者没有办法真正从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($命令);
与此问题是,它会等待该程序关闭。

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?

在code我已经看到了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");
}

这篇关于PHP在Windows机器上;启动后台进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆