gpt4 book ai didi

php - 如何将 Symfony 命令作为 cron 作业执行?

转载 作者:搜寻专家 更新时间:2023-10-31 21:23:44 26 4
gpt4 key购买 nike

我在 symfony 中有这个简单的命令:

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class AuctionEndCommand extends Command
{
protected function configure()
{
error_log(print_r('test',true), 3, "/tmp/error.log");

$this->setName('desktop:auction_end')->setDescription('Execute when auction is end.')->setHelp("Identify winners for auctions");
}
protected function execute(InputInterface $input, OutputInterface $output)
{

// outputs multiple lines to the console (adding "\n" at the end of each line)
$output->writeln([
'User Creator',
'============',
'',
]);

// outputs a message followed by a "\n"
$output->writeln('Whoa!');

// outputs a message without adding a "\n" at the end of the line
$output->write('You are about to ');
$output->write('create a user.');
}
}

现在当我执行:/var/www/myProject/bin/console desktop:auction_end 这个命令工作正常。但是当我尝试在 linux 中作为 cron 执行时,这个脚本不会启动:

在 linux 中我用 sudo 做了:nano crontab -e 和 cron :

* * * * */usr/bin/php/var/www/myProject/bin/console desktop:auction_end >/dev/null

我做错了什么,你能帮帮我吗?提前致谢,对不起我的英语

最佳答案

我可以保持很短。您将需要使用 PHP 来执行控制台。

* * * * * php -q /usr/bin/php /var/www/myProject/bin/console desktop:auction_end > /dev/null 

将您正在测试的 cron 作业的输出写入文件将有助于您调试错误。现在所有输出都丢失了:)

* * * * * php -q /usr/bin/php /var/www/myProject/bin/console desktop:auction_end > /home/<user>/crons/auction_end.cron.txt 

编辑

这可能是你的 php 应该被用作绝对路径。

* * * * * /path/to/php /path/to/bin/console symfony:command

或者甚至通过指定用户来执行命令:

* * * * *  root /usr/bin/php /path/to/bin/console command:to:execute

还要确保 root 用户有权执行您的 symfony 项目中的文件。

关于php - 如何将 Symfony 命令作为 cron 作业执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40860843/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com