avoid recursive calls to the event loop dispatcher
authorMichael Wallner <mike@php.net>
Tue, 23 Aug 2016 09:50:08 +0000 (11:50 +0200)
committerMichael Wallner <mike@php.net>
Tue, 23 Aug 2016 09:50:08 +0000 (11:50 +0200)
package.xml
php_http.h
src/php_http_client_curl.c
tests/client030.phpt [new file with mode: 0644]

index d22b029..352bf47 100644 (file)
@@ -33,7 +33,7 @@ https://mdref.m6w6.name/http
  </lead>
  <date>2016-08-22</date>
  <version>
-  <release>2.6.0beta1</release>
+  <release>2.6.0beta2</release>
   <api>2.6.0</api>
  </version>
  <stability>
index 4f3e4e0..eb022ef 100644 (file)
@@ -13,7 +13,7 @@
 #ifndef PHP_EXT_HTTP_H
 #define PHP_EXT_HTTP_H
 
-#define PHP_PECL_HTTP_VERSION "2.6.0beta1"
+#define PHP_PECL_HTTP_VERSION "2.6.0beta2"
 
 extern zend_module_entry http_module_entry;
 #define phpext_http_ptr &http_module_entry
index 1ec6624..27ebd02 100644 (file)
@@ -2233,16 +2233,17 @@ static int php_http_client_curl_once(php_http_client_t *h)
 {
        php_http_client_curl_t *curl = h->ctx;
 
-       if (curl->ev_ops) {
-               curl->ev_ops->once(curl->ev_ctx);
-       } else {
-               while (CURLM_CALL_MULTI_PERFORM == curl_multi_perform(curl->handle->multi, &curl->unfinished));
-       }
+       if (!h->callback.depth) {
+               if (curl->ev_ops) {
+                       curl->ev_ops->once(curl->ev_ctx);
+               } else {
+                       while (CURLM_CALL_MULTI_PERFORM == curl_multi_perform(curl->handle->multi, &curl->unfinished));
+               }
 
-       php_http_client_curl_responsehandler(h);
+               php_http_client_curl_responsehandler(h);
+       }
 
        return curl->unfinished;
-
 }
 
 static ZEND_RESULT_CODE php_http_client_curl_exec(php_http_client_t *h)
diff --git a/tests/client030.phpt b/tests/client030.phpt
new file mode 100644 (file)
index 0000000..582087f
--- /dev/null
@@ -0,0 +1,35 @@
+--TEST--
+client eventloop recursion
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+include "helper/server.inc";
+
+class test implements SplObserver {
+       function update(SplSubject $client) {
+               $client->once();
+       }
+}
+server("proxy.inc", function($port) {
+       $client = new http\Client;
+       $client->configure([
+                       "use_eventloop" => true,
+       ]);
+       $client->attach(new test);
+       $client->enqueue(new http\Client\Request("GET", "http://localhost:$port/"), function($r) {
+               var_dump($r->getResponseCode());
+       });
+       $client->send();
+});
+
+?>
+===DONE===
+--EXPECTF--
+Test
+int(200)
+===DONE===
\ No newline at end of file