
 Orion Tiller - 2009-06-01 18:40:03
 
I have a php file that stops running in the middle if there is an unsuccessful load_url() function call.  Is there a way to make the rest of the code execute even if the url can't be reached?  Thanks
code
...
$url = "http://www.someurlthatistemporarilydown.com/submit.php";
$result = load_url($url);
//if the url is temporarily down then the code stops and the rest of the code doesn't execute
...
rest of code
Here is the load_url function that is declared before the call to it.
require("http.php");
   function load_url( $url ) {
        $returnvalue = "";
        set_time_limit(0);
    
        $http=new http_class;
    
        $http->timeout=0;
        $http->data_timeout=0;
        $http->debug=0;
        $http->html_debug=0;
        $http->follow_redirect=0;
        $http->user_agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
        
        $error=$http->GetRequestArguments($url,$arguments);
        $error=$http->Open($arguments);
        if($error) die($error);
        $error=$http->SendRequest($arguments);
        if($error) die($error);
        $headers=array();
        $error=$http->ReadReplyHeaders(&$headers);
        if($error) die($error);
        
        for(Reset($headers),$header=0;$header<count($headers);Next($headers),$header++) {
            $header_name=Key($headers);
            if(GetType($headers[$header_name])=="array")
            {
                for($header_value=0;$header_value<count($headers[$header_name]);$header_value++)
                    if ($header_name == "location") { return load_url($headers[$header_name][$header_value]); }
            }
            else
                if ($header_name == "location") { 
                    $redir = $headers[$header_name];
                    $regexp = "http(s?)\:\/\/(.*)\/(.*)";
                    if(preg_match("/$regexp/siU", $redir, $matches)) {
                        $url = $redir;    
                        return load_url($url); 
                    } else {
                        if(preg_match("/$regexp/siU", $url, $matches)) {
                            $url = "http://".$matches[2].str_replace(" ", "%20", $redir);
                            return load_url($url); 
                        } else {
                            return "An Error Has Occurred.";
                        }
                    }                        
                }
            }
        
        for(;;) {
            $error=$http->ReadReplyBody($body,1000);
            if ($error!="" || strlen($body)==0)
                break;
             $returnvalue .= $body;
         }
         return $returnvalue;
    }