Req #80956 [NEW]: Forward PHP streams as extra_fds to curl_multi_wait in curl_multi_select
| From: | asmqb7 at gmail dot com | Date: | Thu, 15 Apr 2021 14:07:50 +0000 |
| Subject: | Req #80956 [NEW]: Forward PHP streams as extra_fds to curl_multi_wait in curl_multi_select | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-233441@lists.php.net to get a copy of this message | ||
From: asmqb7 at gmail dot com
Operating system: Linux
PHP version: 8.0.3
Package: cURL related
Bug Type: Feature/Change Request
Bug description:Forward PHP streams as extra_fds to curl_multi_wait in curl_multi_select
Description:
------------
It's currently not possible to efficiently run a curl_multi request
while simultaneously selecting on other file descriptors. At first
glance, this appears to be trivially easy to completely fix. (I'd
implement it myself but I'm still getting familiar with PHP's
internals.)
According to the cURL documentation at
https://curl.se/libcurl/c/curl_multi_wait.html,
----
CURLMcode curl_multi_wait(CURLM *multi_handle,
struct curl_waitfd extra_fds[],
unsigned int extra_nfds,
int timeout_ms,
int *numfds);
(...Synopsis...)
The calling application may pass additional curl_waitfd structures
which are similar to poll(2)'s
pollfd structure to be waited on in the same call.
----
It would seem fairly straightforward to simply introduce a 3rd parameter
to curl_multi_select():
curl_multi_select (CurlMultiHandle $multi_handle, float $timeout =
1.0, array $extra_fds = []) : int
The additional streams would then be inserted into extra_fds.
** Main question: are there scenarios in PHP (core) where a
Stream-like-object doesn't boil down to a fd? **
FWIW, curl_multi_select() is currently not using extra_fds for anything
else, so implementing this shouldn't step on anything's toes. From
https://github.com/php/php-src/blob/5b01c4863fe9e4bc2702b2bbf66d292d23001a18/ext/curl/multi.c#L186:
186 error = curl_multi_wait(mh->multi, /*extra_fds*/NULL,
/*extra_nfds*/0,
(unsigned long) (timeout * 1000.0), &numfds);
My general use case for this is to be able to achieve proper blocking
polling on a bunch of streams, when one of those streams is a [set of]
cURL requests, for example in the context of async or event loop
frameworks.
IMO such libraries can easily bear the load of intelligently handling
the "stream_select() vs curl_multi_select()?" question - this problem is
endemic to cURL design idiosyncrasies, and cURL's efficiency (and HTTP/3
support, and general batteries-included behavior, etc etc) make it
definitively worth it to plumb through the support described here so the
PHP userspace can be enabled to fully adapt to cURL's way of doing
things.
In my small event loop framework, I've basically had to implement
recurring ticks that ultimately make stream_select() timeout every
100000us so I can then curl_multi_select($mh, /*timeout*/0). This is not
at all particularly efficient, hence this little feature request.
--
Edit bug report at https://bugs.php.net/bug.php?id=80956&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80956&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80956&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80956&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80956&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80956&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80956&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80956&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80956&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80956&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80956&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80956&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80956&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80956&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80956&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80956&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80956&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80956&r=mysqlcfg