PHP on a windows machine; Start process in background(Windows机器上的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");
}
这篇关于Windows机器上的PHP;在后台启动进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Windows机器上的PHP;在后台启动进程
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- Laravel 仓库 2022-01-01