Thread: PHP cron jobs

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    6
    Rep Power
    0

    PHP cron jobs


    Hello,

    If I have a PHP script that takes 2 minutes to run, I was wondering what would happen if it is setup by the cron to run every minute?

    Would the latter not execute until the first is done? Would they interfere with each other and cause conflicts?

    Thanks
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,459
    Rep Power
    594
    Originally Posted by sigurboy
    Hello,

    If I have a PHP script that takes 2 minutes to run, I was wondering what would happen if it is setup by the cron to run every minute?
    It would run every minute.
    Originally Posted by sigurboy
    Would the latter not execute until the first is done?
    It will run whenever cron starts it. Cron does not care (nor does *NIX) if there is another copy of the script already running.
    Originally Posted by sigurboy
    Would they interfere with each other and cause conflicts?

    Thanks
    They can but it depends on what resources they use. This is really a *NIX question not PHP. For example if they are both trying to write to the same file, that will cause problems. If they are trying to read a file that the other is updating then the data being read may not be valid.

    That having been said, if you know the script runs for more than a minute then why would you set cron to run that often? What most admins do in this case is to start the script on boot, then just before it exits, have it issue an 'at' command to kick off another run in 2 minutes. That way it will always run 2 minutes after the last execution regardless of how long it takes to complete.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.

IMN logo majestic logo threadwatch logo seochat tools logo