:100755 100755 d6483ba... 0000000... M httprl.module diff --git httprl.module httprl.module index d6483ba..1cdea0a 100755 --- httprl.module +++ httprl.module @@ -1,5 +1,14 @@ options['timeout'] - timer_read(__FUNCTION__) / 1000; if ($timeout <= 0) { // Stream timed out. - $responses[$id]->error = 'request timed out'; + $responses[$id]->error = 'request timed out, read'; $responses[$id]->code = HTTP_REQUEST_TIMEOUT; $responses[$id]->status = 'Done.'; $responses[$id]->options['timeout'] = $timeout; @@ -407,7 +416,7 @@ function httprl_send_request($fp = NULL, $url = '', $request = '', $options = '' $timeout = $responses[$id]->options['timeout'] - timer_read(__FUNCTION__) / 1000; if ($timeout <= 0) { // Stream timed out. - $responses[$id]->error = 'request timed out'; + $responses[$id]->error = 'request timed out, write'; $responses[$id]->code = HTTP_REQUEST_TIMEOUT; $responses[$id]->status = 'Done.'; $responses[$id]->options['timeout'] = $timeout; @@ -463,6 +472,23 @@ function httprl_send_request($fp = NULL, $url = '', $request = '', $options = '' else { break; } + + // Check for timeouts + foreach ($responses as $id => &$result) { + // Calculate how much time is left of the original timeout value. + $timeout = $result->options['timeout'] - timer_read(__FUNCTION__) / 1000; + if ($timeout <= 0) { + // Stream timed out. + $result->error = 'request timed out, no streams available'; + $result->code = HTTP_REQUEST_TIMEOUT; + $result->status = 'Done.'; + $result->options['timeout'] = $timeout; + fclose($streams[$id]); + unset($streams[$id]); + continue; + } + } + // Sleep for 25ms if there are open streams and no data was transfered. if (!empty($streams) && !$rw_done) { usleep(25000);