Here's what I'm doing with one of our pages, usually without a problem.
<?php
$remote_url="<remote url>";
$fp = fopen("$remote_url", "r")
if(!$fp){
echo "<h2>Message to visitor</h2>\n";
}else {
//further processing
}
?>
How do I get my script to time-out and display a message to teh user when <remote url> takes a 'very' long time to get back?
I've tried this with set_time_limit() and register_shutdown_function(), but this is doesn't work, partly due to teh fact that I can't get my shutdown function to report anything back to the user.
Using fsockopen(), which uses a timeout, also doesn't seem to do the thing since the host is not the problem. I still experience the same timeout problem when I try to access the page (with fgets). see below
<?php
$fp = fsockopen($host, $port, &$err_num, &$err_msg, $timeout);
if ($fp)
{
fputs($fp, "GET $page HTTP/1.0\r\n");
$response = '';
while (!feof($fp)){
$response = fgets($fp, 128);
}
fclose($fp);
}
?>
Anyone out there who can help me along?
Jelle