note 71412 added to function.sys-getloadavg
| From: | scott at corelevel dot com | Date: | Mon, 27 Nov 2006 22:47:47 +0000 |
| Subject: | note 71412 added to function.sys-getloadavg | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-120112@lists.php.net to get a copy of this message | ||
I was having a problem with a large script I need to run - was a loop through about 50,000 records
and downloading several pictures for a bunch of them, and updating the database.
the problem came as I started getting visitors to my site, the server would get behind, run out of
memory, iowait skyrockets, mysql slows down... was a total downhill spiral.
Use this to fix it.
$load = sys_getloadavg();
$sleep=5;
$maxload=2;
if ($load[0] > $maxload) {
sleep($sleep);
echo "Busy server - sleep $sleep seconds<br>";
}
I have to play with the load and the sleep number to find what worked for my script, but now my
server does not bog at all.
----
Server IP: 64.71.164.2
Probable Submitter: 67.183.186.72
----
Manual Page -- http://www.php.net/manual/en/function.sys-getloadavg.php
Edit -- https://master.php.net/note/edit/71412
Del: integrated -- https://master.php.net/note/delete/71412/integrated
Del: useless -- https://master.php.net/note/delete/71412/useless
Del: bad code -- https://master.php.net/note/delete/71412/bad+code
Del: spam -- https://master.php.net/note/delete/71412/spam
Del: non-english -- https://master.php.net/note/delete/71412/non-english
Del: in docs -- https://master.php.net/note/delete/71412/in+docs
Del: other reasons-- https://master.php.net/note/delete/71412
Reject -- https://master.php.net/note/reject/71412
Search -- https://master.php.net/manage/user-notes.php