php forum
php mysql forum
php mysql smarty
 
Topic Options
#280530 - 10/08/04 03:31 AM Does anyone know how to do this?
Twisty Offline
Code Monkey

Registered: 09/26/03
Posts: 524
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.<br /><br />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).<br /><br />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?<br /><br />
Code:
	function CheckAll()<br />	{<br />		$sql = "SELECT id,website,hash,UNIX_TIMESTAMP(lastchecked) AS lastchecked,UNIX_TIMESTAMP(lastupdated) AS lastupdated,webname FROM {$this-&gt;tbl}";<br />		$result = @mysql_query($sql, $this-&gt;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; // &lt;-- configure the URL timeout in seconds<br />                        stream_set_timeout($site, $timeout);<br /><br /><br /> 			if (empty($site))<br />			{<br />				echo "&lt;p&gt;The website {$row['website']} could not be fetched.&lt;/p&gt;\n";<br />			}<br />			else<br />			{<br />				$hash = md5(strip_tags(join('', $site)));<br />				if ($this-&gt;autoupdate)<br />				{<br />					if ($hash != $row['hash'])<br />					{<br />						$sql = "UPDATE {$this-&gt;tbl} SET lastchecked=NOW(),lastupdated=NOW(),hash='{$hash}' WHERE id={$row['id']}";<br />					}<br />					else<br />					{<br />						$sql = "UPDATE {$this-&gt;tbl} SET lastchecked=NOW() WHERE id={$row['id']}";<br />					}<br />					@mysql_query($sql, $this-&gt;id) or die("Unable to perform query: $sql");<br />				}<br />				else<br />				{<br />					if ($hash != $row['hash'])<br />					{<br />						$this-&gt;results[] = $row;<br />					}<br />				}<br />			}<br />		}<br />		@mysql_free_result($result);<br />	}
_________________________
Twisty []http://www.mameworld.info/misc/nana2.gif[/]
MAMEWorld

Top
#280531 - 10/08/04 01:58 PM Re: Does anyone know how to do this? [Re: smoknz28]
Anno Offline
Code Monkey

Registered: 05/23/01
Posts: 562
Loc: Austria
Perhaps try using a different function to get the files,<br />http://php.net/manual/de/features.remote-files.php , fopen and fgets

Top
#280532 - 10/09/04 07:11 PM Re: Does anyone know how to do this? [Re: domain123]
Twisty Offline
Code Monkey

Registered: 09/26/03
Posts: 524
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).<br /><br />I just used preg_replace to eliminate it before the md5 was calculated.
_________________________
Twisty []http://www.mameworld.info/misc/nana2.gif[/]
MAMEWorld

Top



Latest Posts
[7.2.1] - Naked shoutbox
by bellaonline
05/05/12 05:00 PM
[7.x] Stop Forum Spam Integration v0.4
by bellaonline
05/05/12 03:53 PM
Shout Box

(Views)Popular Topics
Known public proxy servers 1689885
Integrated Index Page (IIP) 5.3.1 555705
Finished-[6.5.2] Games Arcade Deluxe v1.9 501236
Integrated Index Page (IIP) 5.1.1 415112
TLD Bv2.1 Released - Threads Links Directory 396822
[6.0x] Who's Online 4.0.0 [Finished] 389412
Finished-[6.5.1] Integrated Index Page (IIP) 6.5 330423
Q & A 298663
Slash UBB 266936
[6.3.x] [beta] Hit Hack 2.0 227970
Forum Stats
13621 Members
59 Forums
37191 Topics
295716 Posts

Max Online: 686 @ 06/28/07 07:04 AM

 

 

 
fusionbb message board php hacks