Jump to content

PHP Challenge: Break And Resume


monkeypaw201

Recommended Posts

if you want to pace the script, use something like sleep() or usleep()

http://us2.php.net/manual/en/function.sleep.php

 

<?php
  $n = 0;
  while(...){
    //do some stuff
    $n++;
    if(!($n % 100))
      sleep(10); //Take a 10 second break every 100 records
  }
?>

or

<?php
  while(...){
    //do some stuff
    usleep(100); //Take a short break
  }
?>

Link to comment
Share on other sites

if you want to pace the script, use something like sleep() or usleep()

http://us2.php.net/manual/en/function.sleep.php

 

<?php
  $n = 0;
  while(...){
    //do some stuff
    $n++;
    if(!($n % 100))
      sleep(10); //Take a 10 second break every 100 records
  }
?>

or

<?php
  while(...){
    //do some stuff
    usleep(100); //Take a short break
  }
?>

Couldn't this possibly trigger max_execution_time

 

Thought about it his script might do that anyways.

Link to comment
Share on other sites

You said this was going to be a cronjob, which is using PHP via the command line interface. When run from CLI max_execution_time is set to unlimited. As for 'server overload', the script will take up an unnoticeable amount of resources while it's sleeping.

 

Edit: To clarify, the amount of time it takes a script to complete is not related to the amount of load on the server.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.