|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2011-04-08 20:38 UTC] jani@php.net
-Package: Feature/Change Request
+Package: cURL related
[2016-07-03 17:06 UTC] cmb@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 04 23:00:01 2025 UTC |
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.