Jump to content

Interesting observation and question


cooldude832

Recommended Posts

I have a cron job I wrote (it gets the value of diffen't metals/currencies from yahoo)

<?php	
$q = "
	SELECT 	
		CurrencyID,
		Abbreviation
	FROM 
		`".CURRENCY_TABLE."`
	WHERE
		Active = '1'
	ORDER BY Name

";
$r = mysql_query($q) or die(mysql_error()."<br /><br />");
if(mysql_num_rows($r) >0){
	while($row = mysql_fetch_assoc($r)){
		$url = "http://finance.yahoo.com/currency/convert?amt=1&from=".$row['Abbreviation']."&to=XAU&submit=Convert";
		$ch = curl_init();
		curl_setopt ($ch, CURLOPT_URL,$url);
		curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
		curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
		curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
		$data = curl_exec ($ch); 
		$pattern = "[yfnc_tabledata1\">]";
		$split = preg_split($pattern,$data);
		$pattern = "[<]";
		$split = preg_split($pattern,$split[4]);
		$rate = $split[0];
		$q = "INSERT INTO `".CURRENCY_PRICE_TABLE."` (PriceTime, CurrencyID, Price) 
		VALUES(NOW(), '".$row['CurrencyID']."', '".input_clean($rate)."')";
		$r2 = mysql_query($q) or die(mysql_error()."<br /><br />".$q);
		curl_close($ch);
	}
}
?>

 

When it runs as a cron the server has no slow downs.

 

When I run it by manually pining it  in my browser and I try and load another page on my site it waits till cron is done then goes and loads the other request.

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/123610-interesting-observation-and-question/
Share on other sites

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.