Apache crashes, probably due to this piece of PHP code. Can you take a look?

I am developing a web application on codeigniter. I wrote this function to get time zone 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 breaks Apache? The application works fine almost every time, but I think that launching this piece of code when there is no Internet connection or a very poor Internet connection (thus, there is no access to any of the used web services) crashes the server. Something like this happened several times, and I think it was due to the loss of internet connection, but I'm not sure what exactly is happening.

[, . 2 -, . .]

: , . Apache . , , , .

2: apache, . , ( , ) . , " ",

[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?
+3
2

Error StackTarace , , :

 $url = "http://ws.geonames.org/timezone?lat={$lat}&lng={$lng}";

somedata -, .

, try/catch , :

try
{
    $url = "http://ws.geonames.org/timezone?lat={$lat}&lng={$lng}";
    $timedata = file_get_contents($url);
    $sxml = simplexml_load_string($timedata);
}
catch(Exception $e)
{
    // log this exception to file
}
return $sxml->timezone;

, . , , - .

+1

, , php.ini allow_url_fopen false, file_get_contents URL-.

0

Source: https://habr.com/ru/post/1747658/


All Articles