【发布时间】:2025-12-18 05:20:06
【问题描述】:
我在 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
我做错了什么,你能帮帮我吗?提前谢谢,对不起我的英语
【问题讨论】:
-
你用的是什么linux发行版/
-
Ubuntu 14.04.3 LTS
-
Cron 作业有
/usr/bin/php而常规命令没有:-? -
sudo crontab -e -u www-data 将任务配置为 www-data 用户。这可以防止文件权限错误。如果是生产环境,我会用 --env=prod 指定环境。