I have a problem with the url where my application is trying to access the timeout. I am trying to catch this timeout and solve this problem using this code:
$timeout = 120; if(false == $handle = @fsockopen($host, $port, $errno, $errstr, $timeout)) { throw new Exception("Could not connect to url: ".$errstr); } $getRequest = "GET {$url} HTTP/1.0\r\n"; $getRequest .= "Host: {$urlParts['host']}\r\n"; $getRequest .= "Connection: close\r\n\r\n"; fwrite($handle, $getRequest); $maxExecutionTime = ini_get('max_execution_time'); set_time_limit($timeout+10); stream_set_timeout($handle, $timeout); $head = fread($handle, 1024); // Read the first 1024 bytes if($maxExecutionTime == 0) { $maxExecutionTime = 30; } set_time_limit($maxExecutionTime); $stream_metadata = stream_get_meta_data($handle); if($stream_metadata['timed_out'] === true) { throw new Exception("Connection timed out"); }
My URL, which I use for the timeout, is behind the firewall, so I canβt use it, but it is designed to sleep () for 5 minutes. When I try to run this code, execution stops at $ head = fread ($ handle, 1024); and after 90 seconds I get 500 errors from the Premature End of Script server. When I examine the debugging level in apache logs, I see:
[Fri Aug 26 11:10:45 2011] [warn] [client 192.168.10.202] mod_fcgid: read timeout from pipe [Fri Aug 26 11:10:45 2011] [error] [client 192.168.10.202] Premature end of script headers: validateUrl.php
with 'validateUrl.php' being the url I am accessing this script through. I am not sure if increasing FcgidIOTimeout to a higher value is safe, as it applies to all my pages. Any ideas / comments?
System Information: PHP version 5.2.13, running Windows NT EPG-WEB 5.2 build 3790 Apache: Apache / 2.2.19 (Win32) mod_fcgid / 2.3.6
source share