From: Michael Wallner <mike@php.net>
Date: Tue, 23 Aug 2016 09:50:08 +0000 (+0200)
Subject: avoid recursive calls to the event loop dispatcher
X-Git-Tag: RELEASE_2_6_0_BETA2~3
X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=e5df73ae2e31faa4e5a7de57409734f4cecd4c4a;p=m6w6%2Fext-http

avoid recursive calls to the event loop dispatcher
---

diff --git a/package.xml b/package.xml
index d22b029..352bf47 100644
--- a/package.xml
+++ b/package.xml
@@ -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>
diff --git a/php_http.h b/php_http.h
index 4f3e4e0..eb022ef 100644
--- a/php_http.h
+++ b/php_http.h
@@ -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
diff --git a/src/php_http_client_curl.c b/src/php_http_client_curl.c
index 1ec6624..27ebd02 100644
--- a/src/php_http_client_curl.c
+++ b/src/php_http_client_curl.c
@@ -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
index 0000000..582087f
--- /dev/null
+++ b/tests/client030.phpt
@@ -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