This function pulls several websites from a table, and checks to see if they were updated using the PHP 'file' function which reads how many bytes the webpage file is and then stores its new MD5 hash along with the last time it was updated, the last time it was checked, but only if it has changed. If it hasn't changed, only the field for the last time it was checked is updated.
The problem is that it checks all the websites at once which freaks out the server if there are too many and they don't all get read fully/correctly. (A few at once are fine however).
So I need a way to check one site at a time, and wait for the result before it goes on to the next one. After all the results are collected, it would then do the update query. Any ideas?
function CheckAll()<br /> {<br /> $sql = "SELECT id,website,hash,UNIX_TIMESTAMP(lastchecked) AS lastchecked,UNIX_TIMESTAMP(lastupdated) AS lastupdated,webname FROM {$this->tbl}";<br /> $result = @mysql_query($sql, $this->id) or die("Unable to perform query: $sql");<br /> while ($row = @mysql_fetch_array($result, MYSQL_ASSOC))<br /> {<br /> $site = array();<br /> set_time_limit(120);<br /> ini_set("max_execution_time",120);<br /><br /> $site = @file($row['website']);<br /><br /> $timeout = 60; // <-- configure the URL timeout in seconds<br /> stream_set_timeout($site, $timeout);<br /><br /><br /> if (empty($site))<br /> {<br /> echo "<p>The website {$row['website']} could not be fetched.</p>\n";<br /> }<br /> else<br /> {<br /> $hash = md5(strip_tags(join('', $site)));<br /> if ($this->autoupdate)<br /> {<br /> if ($hash != $row['hash'])<br /> {<br /> $sql = "UPDATE {$this->tbl} SET lastchecked=NOW(),lastupdated=NOW(),hash='{$hash}' WHERE id={$row['id']}";<br /> }<br /> else<br /> {<br /> $sql = "UPDATE {$this->tbl} SET lastchecked=NOW() WHERE id={$row['id']}";<br /> }<br /> @mysql_query($sql, $this->id) or die("Unable to perform query: $sql");<br /> }<br /> else<br /> {<br /> if ($hash != $row['hash'])<br /> {<br /> $this->results[] = $row;<br /> }<br /> }<br /> }<br /> }<br /> @mysql_free_result($result);<br /> }