Apache crashes, probably because of this piece of php code. Can you have a look?

Posted by Munim on Stack Overflow See other posts from Stack Overflow or by Munim
Published on 2010-05-29T12:17:30Z Indexed on 2010/05/29 12:22 UTC
Read the original article Hit count: 192

Filed under:
|
|

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.]

© Stack Overflow or respective owner

Related posts about php

Related posts about apache