Alee Waqas Mirza
Alee Waqas Mirza

Reputation: 75

running multiple instances of cron at the same time

I have set of some entries in my database to run some scripts in php. So i will run a cron file every few mins to see if for next few mins i have some scripts to run, i will trigger them, what i am wondering what happens if i have a script to be executed at 12:10 which will execute in 5 mins, what happens if i have another request to run the same script at 12:12 while the execution of the first script is not finished yet. Is the file locked till the execution is done? or what?

Its the same file to be executed in different timings.

I think i can do this with the cron tab, but i dont prefer that.

Upvotes: 2

Views: 3456

Answers (2)

Prisoner
Prisoner

Reputation: 27628

It will run the script twice, thrice or as many times it likes. If you only want to run this script one at a time, you can create a lock file and then check to see if it exists. Example:

if(file_exists('/tmp/script.lock')){
  exit();
}
file_put_contents('/tmp/script.lock','');

// execute code

unlink('/tmp/script.lock');

Upvotes: 2

Darrrrrren
Darrrrrren

Reputation: 6088

They will have no problems running simultaneously but bear in mind you could have issues if they will be writing to the same file/database table.

Upvotes: 2

Related Questions