- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
那么,在 Windows 上的 PHP 中:是否可以同时在后台运行可执行文件 和检索其 PID?我推断可以单独完成这两项任务,但不能同时完成。
要使通过 SHELL 启动的进程后台运行,必须使用命令 'start/B "bg"myprog.exe'
并且 SHELL 进程必须在之后立即关闭。
为此,许多人使用 pclose( popen( ... ) )
像这样 pclose( popen( 'start/B "bg"myprog.exe', 'r' ) );
但据我所知,使用 popen 时无法检索 pid
。
因为不可能用 popen 得到 pid
,所以我们必须查看 proc_open。
如果且仅当 bypass_shell
设置为 true 时,我们可以使用 proc_open
检索 exe 的 pid。
如果 bypass_shell
设置为 false(默认值),Windows 将返回 SHELL 的 pid
。有关详细信息,请参阅:https://bugs.php.net/bug.php?id=41052
start/B
命令在 bypass_shell = true
时传递给 proc_open 时失败,因为它跳过 SHELL 并将命令行参数直接发送到 myprog.exe,而 myprog.exe 不会知道如何处理它们。
相反,如果 bypass_shell = false
(默认值)和 proc_close 用于立即关闭 SHELL,myprog.exe 在后台运行,就像使用 pclose( popen( .. . ) )
但是 不正确 pid
被返回(我们得到了 SHELL 的 pid
)。
那么,后台 + 正确的 pid 检索可能吗?
如果不是,下一个最好的是什么?我需要为将部署在共享主机上的 PHP 脚本执行此操作,因此无法安装第三方扩展。我能想到的最好办法是在后台启动 myprog.exe 之前和之后拍摄 tasklist
的快照,然后交叉分析结果。请注意,myprog.exe 可以同时运行。
如果有帮助,尽管应该没什么区别,但 myprog.exe 实际上是 ffmpeg(安装在大多数共享网络主机上)。
// background the process
pclose( popen( 'start /B "bg" ffmpeg.exe', 'r') );
// get the pid using tasklist
exec( 'TASKLIST /NH /FO "CSV" /FI "imagename eq ffmpeg.exe" /FI "cputime eq 00:00:00"', $output );
$output = explode( '","', $output[0] );
$pid = $output[1];
最佳答案
这不完全是 OP 问题的答案,因为它不能在 Windows 服务器上运行,但它可以在任何启用了 exec() 的 linux 服务器上正常运行,因此它可能对某些人有帮助;)
$pidfile = 'myPidFile'; //coule be done better with tempnam(), but for this example will do like that ;)
$outputfile = '/dev/null'; //can be any text file instead of /dev/null. output from executable will be saved there
$cmd = 'sleep 30'; // this would normaly take 30 seconds
exec(sprintf("%s > %s 2>&1 & echo $! > %s", $cmd, $outputfile, $pidfile));
$pid = file_get_contents($pidfile);
echo $pid;
//delete pid file if you want
//unlink($pidfile);
关于php - 使用 PHP 的 proc_open + bypass_shell 在后台运行可执行文件并检索正确的 PID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7161454/
这个问题已经有答案了: How to do case insensitive string comparison? (23 个回答) 已关闭 3 年前。 用户在我的输入栏中写入“足球”,然后执行第 6
啊,不习惯 javascript 中的字符串。 character_id= + id + correct= + correctOrIncorrect 这就是我需要制作成字符串的内容。如果您无法猜测字符
$(function() { var base_price = 0; CalculatePrice(); $(".math1").on('change', function(e) { Calc
我找不到任何文章回答问题:将Spinnaker部署到Spinnaker将管理的同一Kubernetes集群是否安全/正确?我主要是指生产,HA部署。 最佳答案 我认为Spinnaker和Kuberne
我正在使用MSVC在Windows上从源代码(官方源代码发布,而不是从仓库中)构建Qt5(Qt 5.15.0)。 我正在设置环境。变量,依赖项等,然后运行具有1600万个选项的configure,最后
我需要打印一个包含重复单词的数组。我的数组已经可以工作,但我不知道如何正确计算单词数。我已经知道,当我的索引计数器 (i) 为 49 时,并且当 (i) 想要计数到 50 时,我会收到错误,但我不知道
我正在遵循一个指南,该指南允许 Google map 屏幕根据屏幕尺寸禁用滚动。我唯一挣扎的部分是编写一个代码,当我手动调整屏幕大小时动态更改 True/False 值。 这是我按照说明操作的网站,但
我有一个类“FileButton”。它的目的是将文件链接到 JButton,FileButton 继承自 JButton。子类继承自此以使用链接到按钮的文件做有用的事情。 JingleCardButt
我的 friend 数组只返回一个数字而不是所有数字。 ($myfriends = 3) 应该是…… ($myfriends = 3 5 7 8 9 12). 如果我让它进入 while 循环……整个
这个问题在这里已经有了答案: Is there a workaround to make CSS classes with names that start with numbers valid?
我正在制作一个 JavaScript 函数,当调整窗口大小时,它会自动将 div 的大小调整为与窗口相同的宽度/高度。 该功能非常基本,但我注意到在调整窗口大小时出现明显的“绘制”滞后。在 JS fi
此问题的基本视觉效果可在 http://sevenx.de/demo/bootstrap-carousel/inc.carousel/tabbed-slider.html 获得。 - 如果你想看一看。
我明白,如果我想从函数返回一个字符串文字或一个数组,我应该将其声明为静态的,这样当被调用的函数被返回时,内容就不会“消亡”。 但我的问题是,当我在函数内部使用 malloc 分配内存时会怎样? 在下面
在 mySQL 数据库中存储 true/false/1/0 值最合适(读取数据消耗最少)的数据字段是什么? 我以前使用过一个字符长的 tinyint,但我不确定它是否是最佳解决方案? 谢谢! 最佳答案
我想一次读取并处理CSV文件第一行中的条目(例如打印)。我假设使用Unix风格的\n换行符,没有条目长度超过255个字符,并且(现在)在EOF之前有一个换行符。这意味着它是fgets()后跟strto
所以,我们都知道 -1 > 2u == true 的 C/C++ 有符号/无符号比较规则,并且我有一种情况,我想有效地实现“正确”比较。 我的问题是,考虑到人们熟悉的尽可能多的架构,哪种方法更有效。显
**摘要:**文章的标题看似自相矛盾。 本文分享自华为云社区《Java异常处理:如何写出“正确”但被编译器认为有语法错误的程序》,作者: Jerry Wang 。 文章的标题看似自相矛盾,然而我在“正
我有一个数据框,看起来像: dataDemo % mutate_each(funs(ifelse(. == '.', REF, as.character(.))), -POS) # POS REF
有人可以帮助我使用 VBScript 重新格式化/正确格式化带分隔符的文本文件吗? 我有一个文本文件 ^分界如下: AGREE^NAME^ADD1^ADD2^ADD3^ADD4^PCODE^BAL^A
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
我是一名优秀的程序员,十分优秀!