Req #47475 [Opn]: Propose to add curl_multi_timeout() to curl_multi_select(..., 0)
Edit report at https://bugs.php.net/bug.php?id=47475&edit=1
ID: 47475
Updated by: cmb@php.net
Reported by: php at koterov dot ru
Summary: Propose to add curl_multi_timeout() to
curl_multi_select(..., 0)
Status: Open
Type: Feature/Change Request
Package: cURL related
Operating System: *
PHP Version: 5.2.9RC3
Block user comment: N
Private report: N
New Comment:
Related to request #44231.
Previous Comments:
------------------------------------------------------------------------
[2009-02-22 16:12:18] php at koterov dot ru
Description:
------------
I propose to add the following simple modification to curl_multi_select() function. Now it is
greatly miss the functionality to detect the timeout automatically.
ext\curl\multi.c:
...
PHP_FUNCTION(curl_multi_select)
{
zval *z_mh;
php_curlm *mh;
fd_set readfds;
fd_set writefds;
fd_set exceptfds;
int maxfd;
double timeout = 1.0;
struct timeval to;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|d", &z_mh, &timeout) ==
FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(mh, php_curlm *, &z_mh, -1, le_curl_multi_handle_name,
le_curl_multi_handle);
_make_timeval_struct(&to, timeout);
+
+ /* If timeout == 0 is passed, detect it automatically. */
+ if (!to.tv_sec && !to.tv_usec) {
+ long max_tout = 1000;
+ if ((CURLM_OK == curl_multi_timeout(mh->multi, &max_tout)) && (max_tout != -1)) {
+ to->tv_sec = max_tout / 1000;
+ to->tv_usec = (max_tout % 1000) * 1000;
+ }
+ }
+
FD_ZERO(&readfds);
FD_ZERO(&writefds);
FD_ZERO(&exceptfds);
curl_multi_fdset(mh->multi, &readfds, &writefds, &exceptfds, &maxfd);
RETURN_LONG(select(maxfd + 1, &readfds, &writefds, &exceptfds, &to));
}
Reproduce code:
---------------
cURL has built-in ability to detect the minimal delay till a next handle timeout in the pool. But
there is no chance to use this feature in PHP, because there is no such function. So we have to
perform busy wait loops.
Expected result:
----------------
curl_multi_select($h, 0)
waits till the next request timeout at most.
Actual result:
--------------
there is no chance to catch a handle timeout without busy-wait loop now.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=47475&edit=1
Thread (2 messages)