简体   繁体   English

php进程背景

[英]php process background

I've a question about this answer php execute a background process 我有一个关于这个答案的问题php执行后台进程

Can anyone provide me a working simple example to try what the answer explains? 任何人都可以给我一个简单的例子来试试答案解释的吗?

Thanks in advance! 提前致谢!

Alberto 阿尔贝托

On linux box only: 仅在Linux机器上:

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));
?>

in command line: 在命令行中:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM