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
  }
?>

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.