summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierrick Charron <pierrick@php.net>2018-09-17 20:28:44 -0400
committerPierrick Charron <pierrick@php.net>2018-09-17 20:28:44 -0400
commit3bb218a0a776f8673ea8fab1fb311b760afc0860 (patch)
tree6152ad43aa4e78ee24e10b2ae174a7badccdd70c
parentd77ac7b3dc82676f5123a0cfadb86e5afcd1e8ff (diff)
downloadphp-git-3bb218a0a776f8673ea8fab1fb311b760afc0860.tar.gz
Fix 76480: Use curl_multi_wait() so that timeouts are respected
-rw-r--r--NEWS4
-rw-r--r--ext/curl/multi.c18
2 files changed, 21 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index 10a8438963..a7e900145b 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,10 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? 2018, PHP 7.1.23
+- CURL:
+ . Fixed bug #76480 (Use curl_multi_wait() so that timeouts are respected).
+ (Pierrick)
+
- Opcache:
. Fixed bug #76832 (ZendOPcache.MemoryBase periodically deleted by the OS).
(Anatol)
diff --git a/ext/curl/multi.c b/ext/curl/multi.c
index dd1c436bdd..7a41b22ea2 100644
--- a/ext/curl/multi.c
+++ b/ext/curl/multi.c
@@ -190,6 +190,7 @@ PHP_FUNCTION(curl_multi_remove_handle)
}
/* }}} */
+#if LIBCURL_VERSION_NUM < 0x071c00
static void _make_timeval_struct(struct timeval *to, double timeout) /* {{{ */
{
unsigned long conv;
@@ -199,6 +200,7 @@ static void _make_timeval_struct(struct timeval *to, double timeout) /* {{{ */
to->tv_usec = conv % 1000000;
}
/* }}} */
+#endif
/* {{{ proto int curl_multi_select(resource mh[, double timeout])
Get all the sockets associated with the cURL extension, which can then be "selected" */
@@ -206,12 +208,16 @@ PHP_FUNCTION(curl_multi_select)
{
zval *z_mh;
php_curlm *mh;
+ double timeout = 1.0;
+#if LIBCURL_VERSION_NUM >= 0x071c00 /* Available since 7.28.0 */
+ int numfds = 0;
+#else
fd_set readfds;
fd_set writefds;
fd_set exceptfds;
int maxfd;
- double timeout = 1.0;
struct timeval to;
+#endif
CURLMcode error = CURLM_OK;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|d", &z_mh, &timeout) == FAILURE) {
@@ -222,6 +228,15 @@ PHP_FUNCTION(curl_multi_select)
RETURN_FALSE;
}
+#if LIBCURL_VERSION_NUM >= 0x071c00 /* Available since 7.28.0 */
+ error = curl_multi_wait(mh->multi, NULL, 0, (unsigned long) timeout * 1000.0, &numfds);
+ if (CURLM_OK != error) {
+ SAVE_CURLM_ERROR(mh, error);
+ RETURN_LONG(-1);
+ }
+
+ RETURN_LONG(numfds);
+#else
_make_timeval_struct(&to, timeout);
FD_ZERO(&readfds);
@@ -235,6 +250,7 @@ PHP_FUNCTION(curl_multi_select)
RETURN_LONG(-1);
}
RETURN_LONG(select(maxfd + 1, &readfds, &writefds, &exceptfds, &to));
+#endif
}
/* }}} */