diff --git a/httprl.module b/httprl.module index 312abf7..0d9aa91 100755 --- a/httprl.module +++ b/httprl.module @@ -312,7 +312,7 @@ function httprl_send_request($fp = NULL, $url = '', $request = '', $options = '' // Run the loop as long as we have a stream to read/write to. while (!empty($streams)) { - + $rw_done = FALSE; // Set the read and write vars to the streams var. $read = $write = $streams; $except = array(); @@ -345,6 +345,9 @@ function httprl_send_request($fp = NULL, $url = '', $request = '', $options = '' // Read socket. $chunk = fread($r, $responses[$id]->chunk_size); + if (strlen($chunk) > 0) { + $rw_done = TRUE; + } $responses[$id]->data .= $chunk; // Get stream data. $info = stream_get_meta_data($r); @@ -446,6 +449,7 @@ function httprl_send_request($fp = NULL, $url = '', $request = '', $options = '' // All data has been written to the socket. We are read only from here on out. $responses[$id]->status = "Request sent, waiting for response."; } + $rw_done = TRUE; } else { // There is more data to write to this socket. Cut what was sent @@ -459,6 +463,10 @@ function httprl_send_request($fp = NULL, $url = '', $request = '', $options = '' else { break; } + // Sleep for 25ms if there are open streams and no data was transfered. + if (!empty($streams) && !$rw_done) { + usleep(25000); + } } // Check to see if any of the requests where a redirect.