php过程背景 [英] php process background

查看:43
本文介绍了php过程背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对这个答案有疑问 php执行后台进程

I've a question about this answer php execute a background process

任何人都可以给我一个简单的示例来尝试答案的解释吗?

Can anyone provide me a working simple example to try what the answer explains?

提前谢谢!

阿尔贝托

推荐答案

仅在Linux机器上:

On linux box only:

result.php

result.php

<?php
$cmd = 'for i in {1..5}; do date; sleep 2; done';
$outputfile = '/tmp/result.txt';
$pidfile = '/tmp/result.pid';
exec(sprintf("%s > %s 2>&1 & echo $! >> %s", $cmd, $outputfile, $pidfile));
?>

在命令行中:

php result.php;
tail /tmp/result.txt; /* to monitor the results, take 10 seconds to complete */
cat /tmp/result.pid   /* the pid registered */

这篇关于php过程背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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