php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67180 The callback is not called if there is an Exception
Submitted: 2014-05-02 10:49 UTC Modified: 2014-05-02 18:02 UTC
From: francois dot pasini at gmail dot com Assigned:
Status: Not a bug Package: pecl_http (PECL)
PHP Version: 5.5.12 OS: ubuntu server 13.10
Private report: No CVE-ID: None
 [2014-05-02 10:49 UTC] francois dot pasini at gmail dot com
Description:
------------
I'am using the http extension (2.0.6).

If ONE http\Exception\RuntimeException occurs during a call with multiple http\Client::send ALL queries do not call the callback.

If the request on error does not call the callback that can understand this, but ALL the others do not call their own callback, then I think it's a bug.

Test script:
---------------
$urls = ['http://www.google.fr', 'http://www.google.com', 'http://www.notexist.think', 'http://yahoo.com'];
$httpClient = new \http\client();
foreach ($urls as $url) {
    $httpRequest = new \http\Client\Request('GET', $url);
    $httpRequest->setOptions(['redirect' => 10, 'postredir' => \http\Client\Curl\POSTREDIR_ALL]);
    $httpClient->enqueue($httpRequest, function($r){var_dump('callback '.$r->getTransferInfo('effective_url'));return true;});
}
try {
    $httpClient->send();
} catch (\Exception $e) {
    var_dump($e->getMessage());
}

Expected result:
----------------
string(30) "callback http://www.google.fr/"
string(31) "callback http://www.google.com/"
string(35) "callback https://fr.yahoo.com/?p=us"
string(42) "Could not resolve host: www.notexist.think"

OR

string(30) "callback http://www.google.fr/"
string(31) "callback http://www.google.com/"
string(35) "callback https://fr.yahoo.com/?p=us"
string(9) "callback "
string(42) "Could not resolve host: www.notexist.think"

Actual result:
--------------
string(42) "Could not resolve host: www.notexist.think"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-05-02 12:52 UTC] mike@php.net
-Status: Open +Status: Not a bug
 [2014-05-02 12:52 UTC] mike@php.net
Thank you for your report, but this is not a bug.

Please use the more specific API for this sophisticated use case:

while ($httpClient->once()) {
	$httpClient->wait();
}

This will generate a warning instead of an exception and you're able to inspect the error in the callback ($r->getTransferInfo("error"))
 [2014-05-02 18:02 UTC] francois dot pasini at gmail dot com
not a bug ...
Unpredictable behavior is a bug.

I test the use of $httpClient->once()
Behavior is even more unpredictable.
Why a warning and not a http\Exception\RuntimeException ?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 14:01:29 2024 UTC