0

I am using cron to run a php script every minute and I want to lock it so it won't overlap. So my question is, if I lock the cron job with flock, will lock the process of the cron or of the php-script?

2

flock wraps the lock around the executing a command and will hold the lock for as long as that command is running.

If this is your cronjob that runs every minute:

* * * * * /usr/bin/flock -n /tmp/fcj.lockfile /usr/local/bin/frequent_cron_job 

flock will hold the lock for the duration of /usr/local/bin/frequent_cron_job. If that batch job takes longer than a minute, cron won't be able to acquire the lock and won't run that batch again and/or multiple instances of frequent_cron_job concurrently, until that lock has been released.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.