diff options
author | Andreas Gohr <andi@splitbrain.org> | 2013-03-24 13:09:30 +0100 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2013-03-24 13:09:30 +0100 |
commit | 33b8a94705bfbd34fbee5ed24982374e166a80d0 (patch) | |
tree | a3a18bfbc65613d8001630eddf791b93c431833e | |
parent | f2b500f5e7be771601ea1b1bc110337883d7caf2 (diff) | |
download | rpg-33b8a94705bfbd34fbee5ed24982374e166a80d0.tar.gz rpg-33b8a94705bfbd34fbee5ed24982374e166a80d0.tar.bz2 |
stream select parameters need to be reset for each call
-rw-r--r-- | _test/tests/inc/httpclient_http.test.php | 11 | ||||
-rw-r--r-- | inc/HTTPClient.php | 29 |
2 files changed, 24 insertions, 16 deletions
diff --git a/_test/tests/inc/httpclient_http.test.php b/_test/tests/inc/httpclient_http.test.php index 252eb6b65..387eb53aa 100644 --- a/_test/tests/inc/httpclient_http.test.php +++ b/_test/tests/inc/httpclient_http.test.php @@ -204,5 +204,16 @@ class httpclient_http_test extends DokuWikiTest { $this->assertFalse($data === false, 'HTTP response'); $this->assertEquals(2550,strlen($data)); } + + /** + * This address caused trouble with stream_select() + * + * @group internet + */ + function test_wikimatrix(){ + $http = new HTTPClient(); + $data = $http->get('http://www.wikimatrix.org/cfeed/dokuwiki/-/-'); + $this->assertTrue($data !== false, $http->error); + } } //Setup VIM: ex: et ts=4 : diff --git a/inc/HTTPClient.php b/inc/HTTPClient.php index 772b580b2..6d9855e12 100644 --- a/inc/HTTPClient.php +++ b/inc/HTTPClient.php @@ -570,11 +570,6 @@ class HTTPClient { * @author Tom N Harris <tnharris@whoopdedo.org> */ function _sendData($socket, $data, $message) { - // select parameters - $sel_r = null; - $sel_w = array($socket); - $sel_e = null; - // send request $towrite = strlen($data); $written = 0; @@ -586,6 +581,10 @@ class HTTPClient { if(feof($socket)) throw new HTTPClientException("Socket disconnected while writing $message"); + // select parameters + $sel_r = null; + $sel_w = array($socket); + $sel_e = null; // wait for stream ready or timeout (1sec) if(@stream_select($sel_r,$sel_w,$sel_e,1) === false){ usleep(1000); @@ -615,11 +614,6 @@ class HTTPClient { * @author Tom N Harris <tnharris@whoopdedo.org> */ function _readData($socket, $nbytes, $message, $ignore_eof = false) { - // select parameters - $sel_r = array($socket); - $sel_w = null; - $sel_e = null; - $r_data = ''; // Does not return immediately so timeout and eof can be checked if ($nbytes < 0) $nbytes = 0; @@ -637,6 +631,10 @@ class HTTPClient { } if ($to_read > 0) { + // select parameters + $sel_r = array($socket); + $sel_w = null; + $sel_e = null; // wait for stream ready or timeout (1sec) if(@stream_select($sel_r,$sel_w,$sel_e,1) === false){ usleep(1000); @@ -665,21 +663,20 @@ class HTTPClient { * @author Tom N Harris <tnharris@whoopdedo.org> */ function _readLine($socket, $message) { - // select parameters - $sel_r = array($socket); - $sel_w = null; - $sel_e = null; - $r_data = ''; do { $time_used = $this->_time() - $this->start; if ($time_used > $this->timeout) throw new HTTPClientException( - sprintf('Timeout while reading %s (%.3fs)', $message, $time_used), + sprintf('Timeout while reading %s (%.3fs) >%s<', $message, $time_used, $r_data), -100); if(feof($socket)) throw new HTTPClientException("Premature End of File (socket) while reading $message"); + // select parameters + $sel_r = array($socket); + $sel_w = null; + $sel_e = null; // wait for stream ready or timeout (1sec) if(@stream_select($sel_r,$sel_w,$sel_e,1) === false){ usleep(1000); |