Skip to content

Commit cb6025c

Browse files
authored
1 parent b7fd773 commit cb6025c

File tree

6 files changed

+111
-1
lines changed

6 files changed

+111
-1
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ PHP NEWS
55
- COM:
66
. Fix property access of PHP objects wrapped in variant. (cmb)
77

8+
- Curl:
9+
. Added curl_multi_get_handles(). (timwolla)
10+
811
- DOM:
912
. Added Dom\Element::$outerHTML. (nielsdos)
1013

UPGRADING

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ PHP 8.5 UPGRADE NOTES
7878
6. New Functions
7979
========================================
8080

81+
- Curl:
82+
. curl_multi_get_handles() allows retrieving all CurlHandles current
83+
attached to a CurlMultiHandle. This includes both handles added using
84+
curl_multi_add_handle() and handles accepted by CURLMOPT_PUSHFUNCTION.
85+
8186
- PGSQL:
8287
. pg_close_stmt offers an alternative way to close a prepared
8388
statement from the DEALLOCATE sql command in that we can reuse

ext/curl/curl.stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3702,6 +3702,8 @@ function curl_upkeep(CurlHandle $handle): bool {}
37023702

37033703
function curl_multi_add_handle(CurlMultiHandle $multi_handle, CurlHandle $handle): int {}
37043704

3705+
function curl_multi_get_handles(CurlMultiHandle $multi_handle): array {}
3706+
37053707
function curl_multi_close(CurlMultiHandle $multi_handle): void {}
37063708

37073709
function curl_multi_errno(CurlMultiHandle $multi_handle): int {}

ext/curl/curl_arginfo.h

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/curl/multi.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,29 @@ PHP_FUNCTION(curl_multi_remove_handle)
174174
}
175175
/* }}} */
176176

177+
PHP_FUNCTION(curl_multi_get_handles)
178+
{
179+
zval *z_mh;
180+
php_curlm *mh;
181+
182+
ZEND_PARSE_PARAMETERS_START(1, 1)
183+
Z_PARAM_OBJECT_OF_CLASS(z_mh, curl_multi_ce)
184+
ZEND_PARSE_PARAMETERS_END();
185+
186+
mh = Z_CURL_MULTI_P(z_mh);
187+
188+
array_init(return_value);
189+
zend_llist_position pos;
190+
zval *pz_ch;
191+
192+
for (pz_ch = (zval *)zend_llist_get_first_ex(&mh->easyh, &pos); pz_ch;
193+
pz_ch = (zval *)zend_llist_get_next_ex(&mh->easyh, &pos)) {
194+
195+
Z_TRY_ADDREF_P(pz_ch);
196+
add_next_index_zval(return_value, pz_ch);
197+
}
198+
}
199+
177200
/* {{{ Get all the sockets associated with the cURL extension, which can then be "selected" */
178201
PHP_FUNCTION(curl_multi_select)
179202
{
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
--TEST--
2+
array curl_multi_get_handles ( CurlMultiHandle $mh );
3+
--EXTENSIONS--
4+
curl
5+
--FILE--
6+
<?php
7+
$urls = array(
8+
"file://".__DIR__."/curl_testdata1.txt",
9+
"file://".__DIR__."/curl_testdata2.txt",
10+
);
11+
12+
$mh = curl_multi_init();
13+
$map = new WeakMap();
14+
15+
foreach ($urls as $url) {
16+
echo "Initializing {$url}.", PHP_EOL;
17+
$ch = curl_init($url);
18+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
19+
curl_multi_add_handle($mh, $ch);
20+
printf("%d handles are attached\n", count(curl_multi_get_handles($mh)));
21+
$map[$ch] = $url;
22+
}
23+
24+
do {
25+
$status = curl_multi_exec($mh, $active);
26+
if ($status !== CURLM_OK) {
27+
throw new \Exception(curl_multi_strerror(curl_multi_errno($mh)));
28+
}
29+
30+
if ($active) {
31+
$activity = curl_multi_select($mh);
32+
if ($activity === -1) {
33+
throw new \Exception(curl_multi_strerror(curl_multi_errno($mh)));
34+
}
35+
}
36+
37+
while (($info = curl_multi_info_read($mh)) !== false) {
38+
if ($info['msg'] === CURLMSG_DONE) {
39+
$handle = $info['handle'];
40+
$url = $map[$handle];
41+
echo "Request to {$url} finished.", PHP_EOL;
42+
printf("%d handles are attached\n", count(curl_multi_get_handles($mh)));
43+
curl_multi_remove_handle($mh, $handle);
44+
printf("%d handles are attached\n", count(curl_multi_get_handles($mh)));
45+
46+
if ($info['result'] === CURLE_OK) {
47+
echo "Success.", PHP_EOL;
48+
} else {
49+
echo "Failure.", PHP_EOL;
50+
}
51+
}
52+
}
53+
} while ($active);
54+
55+
printf("%d handles are attached\n", count(curl_multi_get_handles($mh)));
56+
57+
?>
58+
--EXPECTF--
59+
Initializing %scurl_testdata1.txt.
60+
1 handles are attached
61+
Initializing %scurl_testdata2.txt.
62+
2 handles are attached
63+
Request to %scurl_testdata%d.txt finished.
64+
2 handles are attached
65+
1 handles are attached
66+
Success.
67+
Request to %scurl_testdata%d.txt finished.
68+
1 handles are attached
69+
0 handles are attached
70+
Success.
71+
0 handles are attached

0 commit comments

Comments
 (0)