Bug #67584 [Asn]: Misleading error in pecl_http 2.0.x

From: Date: Mon, 07 Jul 2014 15:48:21 +0000
Subject: Bug #67584 [Asn]: Misleading error in pecl_http 2.0.x
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-186504@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67584&edit=1 ID: 67584 User updated by: marcus at synchromedia dot co dot uk Reported by: marcus at synchromedia dot co dot uk Summary: Misleading error in pecl_http 2.0.x Status: Assigned Type: Bug Package: HTTP related Operating System: OS X PHP Version: 5.4.30 Assigned To: mike Block user comment: N Private report: N New Comment: Thanks for getting back to me. If I issue my requests with: while (@$client->once()) { $client->wait(); } Where would failure information be stored when iterating over the output of getResponse afterwards? Dealing with them inside that loop seems like it might interfere with the parallel nature of the requests? If not, how can I get a handle on which Request object caused the error, assuming they could complete or fail in random order? When you say "I'll fix that", do you mean that getResponse will return a proper Response instance with error info instead of complaining it's a Message? I'm using this in two places - a link checker and an image grabber - where I want all the requests to happen (even if some fail), in parallel, and assess the responses afterwards. I'm also getting consistent segfaults in the test script on the first line inside the getResponse loop if I step through it with xdebug (in PHPStorm). I don't know if that's your department. Previous Comments: ------------------------------------------------------------------------ [2014-07-07 14:52:50] mike@php.net I'm sorry you've had such a hard time using this library. As already noted at your comment in the docs, all of those methods are actually http\Message methods. http\Client\Response is just a thin layer adding exactly those few methods as documented. If the response raises that error (thanks for spotting thy typo) it basically means a response was never received and the message is completely blank. Basically an uininitialized http\Message. I'll fix that. Now to your use case. If an exception occurs everything else currently executing is stopped of course. If the first thing that happens is a DNS exception nothing else happened. You have to use the more fine grained API if you want information of the single requests you were issuing; see http://devel-m6w6.rhcloud.com/mdref/http/Client/once which throws warnings instead of exceptions. ------------------------------------------------------------------------ [2014-07-07 13:40:15] marcus at synchromedia dot co dot uk Description: ------------ I'm using pecl_http 2.0.x. I'm issuing multiple requests in one go using enqueue, and if a transfer fails it throws an exception which I catch and ignore because the details of it will be revealed when inspecting Responses afterwards. So I loop over the responses provided by the client, all of which are http\Response instances, and yet I receive this error when calling getResponseCode: PHP Warning: http\Message::getResponseCode(): http\Message is not if type response (note the mis-spelling of 'of', probably makes it easier to track down). So the http\Client::getResponse is returning http\Response objects as expected, but when I call a method on one to get its status, it complains that it's another type?? It's hard to tell what it's meant to be doing because the Response class is almost entirely undocumented: http://devel-m6w6.rhcloud.com/mdref/http/Client/Response Test script: --------------- <?php $urls = array( 'http://www.apple.com/', 'http://www.google.com/', 'http://www.googlesdfasdfsadfsdf.com/' ); $client = new http\Client; $client->setOptions(array( 'timeout' => 5, 'connecttimeout' => 5, )); foreach ($urls as $url) { $client->enqueue(new http\Client\Request('GET', $url)); } try { //Issue all the requests $client->send(); } catch (http\Exception $e) { //Ignore exceptions - they will have bad response codes too } //Parse responses while ($response = $client->getResponse()) { echo get_class($response)."\n"; $url = $response->getTransferInfo('effective_url'); if ($response->getResponseCode() == 200) { $e = $response->getBody(); //echo $e; } } Expected result: ---------------- I'm not sure what it's meant to do because it's not documented, but it certainly shouldn't be breaking weirdly like this. Actual result: -------------- http\Client\Response http\Client\Response http\Client\Response PHP Warning: http\Message::getResponseCode(): http\Message is not if type response in test.php on line 25 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=67584&edit=1

« previous php.bugs (#186504) next »