I am working on the development of a web based application on codeigniter. I wrote this function to get the timezone data for any city or address.
function gettimezone($address)
{
$_url = 'http://api.local.yahoo.com/MapsService/V1/geocode';
$_url .= sprintf('?appid=%s&location=%s',"phpclasses",rawurlencode($address));
$_result = false;
if($_result = file_get_contents($_url)) {
preg_match('!<Latitude>(.*)</Latitude><Longitude>(.*)</Longitude>!U', $_result, $_match);
$lng = $_match[2];
$lat = $_match[1];
$url = "http://ws.geonames.org/timezone?lat={$lat}&lng={$lng}";
$timedata = file_get_contents($url);
$sxml = simplexml_load_string($timedata);
return $sxml->timezone;
}
else
return false;
}
I am working on Windows 7 and xampp 1.7 (php 5.2.8).
Is there any possible scenario where this piece of code would crash Apache? The application runs fine almost everytime, but I think running this piece of code when there is no internet connectivity or very poor internet connectivity (thereby no access to either of the webservices I have used) brings down the server. Something like this happened a few times and I think it was due to loss of internet connectivity but I am not sure what exactly is going on.
[ By the way, feel free to use this piece of code. Makes 2 web service calls so don't use to too often in your application. Consider storing the results in a database.]
Edit: This piece of code and my application works perfectly, almost every time. It just crashed Apache a couple of times a few days ago. And I think its this function is the culprit as this was one of the things that was added just before those crashes.
Edit 2: Here is a small snippet of my apache error log that doesn't look right. This is there in the log a few times, and I think(quite sure actually) it corresponds to the server crash. Apart from this, there are a few "file does not exist" errors, which won't crash the server
[Mon May 24 12:14:26 2010] [notice] Parent: child process exited with status 3221225477 -- Restarting.
[Mon May 24 12:15:29 2010] [warn] pid file c:/xampp/apache/logs/httpd.pid overwritten -- Unclean shutdown of previous Apache run?