PHP EXEC在后台使用和放大器;不管用 [英] PHP exec in background using & is not working

查看:137
本文介绍了PHP EXEC在后台使用和放大器;不管用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用这code在Ubuntu 13.04,

I am using this code on Ubuntu 13.04,

$cmd = "sleep 20 &> /dev/null &";
exec($cmd, $output);

虽然它实际上坐在那里20秒和等待:/平时使用时正常工作&安培; 来一个进程发送到后台,但在这台机器的PHP只是不会做它:/结果
这可能是造成这?

Although it actually sits there for 20 seconds and waits :/ usually it works fine when using & to send a process to the background, but on this machine php just won't do it :/
What could be causing this??

推荐答案

尝试

<?PHP
$cmd = '/bin/sleep';
$args = array('20');

$pid=pcntl_fork();
if($pid==0)
{
  posix_setsid();
  pcntl_exec($cmd,$args,$_ENV);
  // child becomes the standalone detached process
}

echo "DONE\n";

我测试了它的工作原理。
在这里,你先用叉子叉PHP的过程,然后exceute你的任务。

I tested it for it works. Here you first fork the php process and then exceute your task.

或者,如果PCNTL模块不是availabil使用:

Or if the pcntl module is not availabil use:

<?PHP

$cmd = "sleep 20 &> /dev/null &";
exec('/bin/bash -c "' . addslashes($cmd) . '"');

这篇关于PHP EXEC在后台使用和放大器;不管用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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