Prevent empty log lines and a couple of include cleanups.
[fa-stable.git] / includes / remote_url.inc
index 8b033806bffd92de9bf13d65000885d99c12934e..4cb88e12d1fbfb91d4e97caee58b1a67599b6144 100644 (file)
@@ -19,6 +19,9 @@ function url_get_contents($url, $timeout=10)
        // get the host name and url path
        $parsedUrl = parse_url($url);
 
+       if (@$parsedUrl['scheme'] == 'file')
+               return file_get_contents($parsedUrl['path']);
+
        $host = $parsedUrl['host'];
 
        if (isset($parsedUrl['path'])) {
@@ -40,7 +43,6 @@ function url_get_contents($url, $timeout=10)
        }
 
        $response = '';
-
        // connect to the remote server
        $fp = @fsockopen($host, $port, $errno, $errstr, $timeout );
        if( !$fp ) {
@@ -60,11 +62,13 @@ function url_get_contents($url, $timeout=10)
                        "Referer: http://$host\r\n\r\n");
 
                // retrieve the response from the remote server
-               $len =0;
+               $unblocked=0;
+
                while ($line = fread($fp, 4096)) {
                        $response .= $line;
-//                     if ($host=='localhost')
-//                             stream_set_blocking($fp, 0); // just after connection switch to nonblocking mode
+                       if (strpos($host,'localhost') !== false && !$unblocked++)
+                               stream_set_blocking($fp, 0); // just after connection switch to nonblocking mode
+                       usleep(10);
                }
                fclose( $fp );
 
@@ -83,6 +87,8 @@ function url_get_contents($url, $timeout=10)
 function url_copy($from, $to, $timeout=10)
 {
        $f = fopen($to, 'wb');
-       fwrite($f, url_get_contents($from, $timeout));
+       if (!$f || !fwrite($f, url_get_contents($from, $timeout)))
+               return false;
        fclose($f);
+       return true;
 }