Previous Thread
Next Thread
Print Thread
Rate Thread
Joined: Sep 2003
Posts: 488
Code Monkey
Code Monkey
Joined: Sep 2003
Posts: 488
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?

Code
	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 />	}

Sponsored Links
Joined: May 2001
Posts: 550
Code Monkey
Code Monkey
Offline
Joined: May 2001
Posts: 550
Perhaps try using a different function to get the files,
http://php.net/manual/de/features.remote-files.php , fopen and fgets

Joined: Sep 2003
Posts: 488
Code Monkey
Code Monkey
Joined: Sep 2003
Posts: 488
Actually I just realized that it already works the way I had it (the sites' ads were inserting varying text between the noscript tags on every refresh which caused the length to always differ).

I just used preg_replace to eliminate it before the md5 was calculated.


Link Copied to Clipboard
Donate Today!
Donate via PayPal

Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.

Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
Recommended Hosts
We have personally worked with and recommend the following Web Hosts:
Stable Host
bluehost
InterServer
Visit us on Facebook
Member Spotlight
isaac
isaac
California
Posts: 1,157
Joined: July 2001
Forum Statistics
Forums63
Topics37,573
Posts293,925
Members13,849
Most Online5,166
Sep 15th, 2019
Today's Statistics
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
Top Posters
AllenAyres 21,079
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,833
Greg Hard 4,625
Top Posters(30 Days)
Top Likes Received
isaac 82
Gizmo 20
Brett 7
WebGuy 2
Morgan 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2024 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20221218)