We have a command in symfony that is being exceuted via a minutely CRON. The command is creating, writing records from the database to the CSV file and then downloading CSV file. I need to know if a command is executed once and the CSV process has started then on the next execution of the cron after a minute will the previous execution stop or will continue in the background ?
1 Answer
They will run in parallel as you would have started it from the console, so if that is undesirable, you would want to make sure that the previous process has finished or make the cron jobs run on bigger interval (or both).
You can use in cron * * * * * /usr/bin/pgrep "console" > /dev/null || bin/console ... or something like that to check if there is an unfinished job already running
3 Comments
DavidG
thanks for your answer. I've found a method to lock a process, in my case the command that is going to be executed via CRON, so when the previous command execution hasn't finished the next CRON won't execute the script. Here's the link: stackoverflow.com/a/34412312/13345631
DavidG
I also want to know does commands, running via PHP CLI get a timeout if the script is time taking ? It mentioned here in the doc that for PHP CLI the
max_execution_time is set 0 by default but just want to confirm. php.net/manual/en/info.configuration.php#ini.max-execution-timevenimus
it does not have execution limit, will run forever. It has a memory_limit though, so if there is a memory leak in your code it will eventually stop unexpectedly. Locks are good solution but i just provided a simple solution that does not mess with the code.