简体   繁体   English

在symfony中执行cron工作

[英]Run cron job in symfony

I'm using docker for may symfony application and I need to run a cron job every minute. 我将docker用于may symfony应用程序,并且需要每分钟运行一次cron作业。 So basically I have a command my:command which I normally run like this: app/console my:command I tried several variations but all were unsuccessful. 所以基本上我有一个命令my:command ,我通常这样运行: app/console my:command我尝试了几种变体,但是都没有成功。 So my question is how can I run a cron job? 所以我的问题是我该如何执行Cron工作? Here are some of my tries: 这是我的一些尝试:

First: 第一:

* * * * * cd /usr/lib/myProject && app/console my:command >> /usr/lib/myProject/app/logs/log1.log

Second: 第二:

* * * * * /usr/lib/myProject/app/console my:command >> /usr/lib/myProject/app/logs/log1.log

is your cronjob in your docker Image or outside? 您的cronjob是在docker映像中还是在外部? If it's outside your should check that php is already installed. 如果在外面,则应检查是否已安装php。 You can run the command whereis php or which php to get to know the absolute path to the php binary. 您可以运行命令whereis phpwhich php来了解php二进制文件的绝对路径。 Then you put the path for the app/console command. 然后,放置app / console命令的路径。

If your cronjob is inside of your docker container, you must to check that the cron daemon should run as a process. 如果您的cronjob在docker容器中,则必须检查cron守护进程应作为进程运行。 Use docker ps for it or go inside your container and execute ps awwx . 使用docker ps或进入容器并执行ps awwx If crond not already running I would suggest you take a look at supervisord. 如果crond尚未运行,建议您看一下supervisor。 With this software you can run more than one process in one docker container. 使用此软件,您可以在一个Docker容器中运行多个进程。

At least posibility you can configure the cronjob outside but execute the command inside of the container. 至少,您可以在外部配置cronjob,但可以在容器内部执行命令。 To do this you should prepand docker exec command in your crontab. 为此,您应该在crontab中预装docker docker exec命令。

Hope it helps. 希望能帮助到你。

Cheers, Robin 干杯,罗宾

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM