Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php,如何在后台为消费者创建/保持服务?_Php_Ubuntu_Amqp - Fatal编程技术网

php,如何在后台为消费者创建/保持服务?

php,如何在后台为消费者创建/保持服务?,php,ubuntu,amqp,Php,Ubuntu,Amqp,我正在运行一个ec2实例,使用ubuntu 12.04 我正在使用aws结构,现在我正在尝试实现一个消费工人,它将使用一个sqs队列(MSG队列,不是很重要) 为此,我创建了一个php文件,该文件“收获”队列30秒。 在顶部,我有一个crontab,每30秒运行一次这个页面 什么是更优雅/合适的解决方案?我如何创建一个后台php进程,如何检查它是否处于活动状态,如果需要,如何杀死它并重新启动它 只是澄清一下-我想问的是使用队列的进程,而不管选择了哪个/什么mechanizem(sqs、rabb

我正在运行一个ec2实例,使用ubuntu 12.04

我正在使用aws结构,现在我正在尝试实现一个消费工人,它将使用一个sqs队列(MSG队列,不是很重要)

为此,我创建了一个php文件,该文件“收获”队列30秒。 在顶部,我有一个crontab,每30秒运行一次这个页面

什么是更优雅/合适的解决方案?我如何创建一个后台php进程,如何检查它是否处于活动状态,如果需要,如何杀死它并重新启动它

  • 只是澄清一下-我想问的是使用队列的进程,而不管选择了哪个/什么mechanizem(sqs、rabbitMQ)
谢谢你的帮助

我建议()。它是一个基于新兴标准的完整且高度可靠的企业消息传递系统。检查他们的例子


使用类进程(我从php文档中复制)创建一个监视脚本,如果进程未运行,它将启动您的辅助脚本。监视器脚本可以将pid保存在文件中

然后简单地将监视器添加到crontab

class Process{
    private $pid;
    private $command;

    public function __construct($cl=false){
        if ($cl != false){
            $this->command = $cl;
            $this->runCom();
        }
    }
    private function runCom(){
        $command = 'nohup '.$this->command.' > /dev/null 2>&1 & echo $!';
        exec($command ,$op);
        $this->pid = (int)$op[0];
    }

    public function setPid($pid){
        $this->pid = $pid;
    }

    public function getPid(){
        return $this->pid;
    }

    public function status(){
        $command = 'ps -p '.$this->pid;
        exec($command,$op);
        if (!isset($op[1]))return false;
        else return true;
    }

    public function start(){
        if ($this->command != '')$this->runCom();
        else return true;
    }

    public function stop(){
        $command = 'kill '.$this->pid;
        exec($command);
        if ($this->status() == false)return true;
        else return false;
    }
}

您好,谢谢,我不确定我是否能够发现相关的php代码,如果有的话。他们似乎在运行一个简单的循环,但我没有发现任何维护此代码的代码(即保持/检查此进程是否处于活动状态),也许我只是错过了它。