php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #47475 Propose to add curl_multi_timeout() to curl_multi_select(..., 0)
Submitted: 2009-02-22 16:12 UTC Modified: 2016-07-03 17:06 UTC
Votes:3
Avg. Score:4.3 ± 0.9
Reproduced:3 of 3 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: php at koterov dot ru Assigned:
Status: Open Package: cURL related
PHP Version: 5.2.9RC3 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
43 + 6 = ?
Subscribe to this entry?

 
 [2009-02-22 16:12 UTC] 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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [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
Related to request #44231.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 08:01:28 2024 UTC