簡體   English   中英

Crontab不要運行php命令

[英]Crontab do not run the php command

我正在使用帶有pheanstalk php庫的Symfony 3框架。 我在使用Linux Debian Jesse的服務器上運行該應用程序。 作業創建可以正常進行,如果從終端運行該工作程序,它應該可以正常工作。 但是,當我將命令添加到crontab時,我看到該命令不起作用。 / var / main / user中沒有任何日志可幫助我進行調試。 我會很高興為您提供任何幫助。

這是我的工作程序命令(僅是execute函數):

protected function execute(InputInterface $input, OutputInterface $output)
{
    $output->writeln("\n<info>Beanstalk worker service started</info>");
    $tubes = $this->getContainer()->get('app.job_manager.power_plant')->getTubes();
    if ($input->getOption('one-check')) {
        // run once
        foreach ($tubes as $tubeName) {
            if ($tubeName != "default") {
                $this->getContainer()->get('app.queue_manager')->fetchQueue($tubeName);
            }
        }
        $output->writeln("\n<info>Beanstalk worker completed check and stoped</info>");
    } else {
        // run forever
        set_time_limit(0);
        max_execution_time(0);
        while (1) {
            foreach ($tubes as $tubeName) {
                if ($tubeName != "default") {
                    $this->getContainer()->get('app.queue_manager')->fetchQueue($tubeName);
                }
            }
        }
        $output->writeln("\n<info>Beanstalk worker stoped</info>");
    }
}

這是我的app.queue_manager函數,用於從隊列中獲取作業並運行命令:

public function fetchQueue($tubeName)
{
    if ($this->pheanstalk->getConnection()->isServiceListening()) {
        while (true === is_object($job = $this->pheanstalk->watch($tubeName)->ignore('default')->reserve(self::WATCH_TIMEOUT))) {
            $data = json_decode($job->getData(), true);
            $this->worker($data);
            $this->pheanstalk->delete($job);
        }
    }
}

和工人運行命令

public function worker($data)
{
    $application = new Application($this->kernel);
    $application->setAutoExit(false);

    $parameters = [];
    $parameters['command'] = $data['command'];
    foreach ($data['meta'] as $key => $param) {
        $parameters[$key] = $param;
    }

    $input = new ArrayInput($parameters);
    $output = new NullOutput();

    return $application->run($input, $output);
}

這是我的crontab不起作用:

@reboot /usr/bin/php /var/www/mose-base/bin/console beanstalk:worker:start

我創建了另一個可以正常工作的cron選項卡。 它每15分鍾工作一次,不同之處在於它沒有無限循環(while(1)),因此它僅通過管一次,然后結束。 但這不是我想要的。 我想要像我用第一個crontab創建它一樣一直工作的無限循環:

*/15 * * * * /usr/bin/php /var/www/mose-base/bin/console beanstalk:worker:start --one-check

如果它在控制台中有效,則不適用於您的文件用戶權限。 核實。

您可以通過此工作通過電子郵件報告錯誤

*/15 * * * * /usr/bin/php /var/www/mose-base/bin/console beanstalk:worker:start --one-check 2>&1 | mail -s "mysql_dump" example@mail.example

我用rc.local。 它解決了問題。 Tnx Freudian滑移

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM