Jack Norton
10-10-2006, 02:36 AM
Hello, tecnical php question :) I have a script that checks if a file is present in one of my mirror:
<?php
function url_exists($url)
{
$handle = @fopen($url, "r");
if ($handle === false)
return false;
fclose($handle);
return true;
}
?>
so I can check, for example, if a demo exist and download it when user click on download (in case one server goes down I can choose another instead of displaying a bad "timeout" page!).
My problem is that is quite slow - takes even 4-5 seconds before giving a response. Was wondering if there's a way to speed up things in php! like check if file exist and if the other server doesn't give any response after 1 second, mark it as timeout/failed and goes to next one :)
EDIT: OK found the solution, sorry! was enough to put this line:
$old = ini_set('default_socket_timeout', $timeout);
<?php
function url_exists($url)
{
$handle = @fopen($url, "r");
if ($handle === false)
return false;
fclose($handle);
return true;
}
?>
so I can check, for example, if a demo exist and download it when user click on download (in case one server goes down I can choose another instead of displaying a bad "timeout" page!).
My problem is that is quite slow - takes even 4-5 seconds before giving a response. Was wondering if there's a way to speed up things in php! like check if file exist and if the other server doesn't give any response after 1 second, mark it as timeout/failed and goes to next one :)
EDIT: OK found the solution, sorry! was enough to put this line:
$old = ini_set('default_socket_timeout', $timeout);