Hello,
I have list of functions which pull information from various servers. The return value is then tossed into an array for parsing latter on in the application.
The problem I am experiencing is some servers are “unreliable” and may make the application run really slow. I would like to have it so each function has a timeout of 10 seconds and if it does not return anything it jumps to the next function. I have already messed around with set_timeout and it does not seem to function the way I have intended.
This is what I currently have….
error_reporting(0);
function return_information($server_info) {
try { $Array[] = server_1($server_info); }
catch (Exception $e) { report_bad_server($e,'server_1'); }
try { $Array[] = server_2($server_info); }
catch (Exception $e) { report_bad_server($e,'Amazon server_2'); }
try { $Array[] = server_3($server_info); }
catch (Exception $e) { report_bad_server($e,'Amazon server_3'); }
try { $Array[] = server_4($server_info); }
catch (Exception $e) { report_bad_server$e,'Bookbyte server_4'); }
return $Array;
}
function report_bad_server($exception,$server) {
$message = "Exception Bad server ".$server."\n";
$message .= 'Error message: '.$e->getMessage()."\n";
$message .= 'Error code: '.$e->getCode()."\n";
$message .= 'File and line: '.$e->getFile().'('.$e->getLine().")\n";
$message .= 'Trace: '.$e->getTraceAsString()."\n";
mail("****@****.com","Error - Server Fault",$message);
}
I need it so I can set a 10 second time out on each server_3($server_info) function call.
Thank you for your assistance.