xref: /PHP-8.2/ext/curl/multi.c (revision cc67220e)
1 /*
2    +----------------------------------------------------------------------+
3    | Copyright (c) The PHP Group                                          |
4    +----------------------------------------------------------------------+
5    | This source file is subject to version 3.01 of the PHP license,      |
6    | that is bundled with this package in the file LICENSE, and is        |
7    | available through the world-wide-web at the following url:           |
8    | https://www.php.net/license/3_01.txt                                 |
9    | If you did not receive a copy of the PHP license and are unable to   |
10    | obtain it through the world-wide-web, please send a note to          |
11    | license@php.net so we can mail you a copy immediately.               |
12    +----------------------------------------------------------------------+
13    | Author: Sterling Hughes <sterling@php.net>                           |
14    +----------------------------------------------------------------------+
15 */
16 
17 #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
18 
19 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
22 
23 #include "php.h"
24 #include "Zend/zend_smart_str.h"
25 
26 #include "curl_private.h"
27 
28 #include <curl/curl.h>
29 #include <curl/multi.h>
30 
31 #ifdef HAVE_SYS_SELECT_H
32 #include <sys/select.h>
33 #endif
34 
35 #ifdef HAVE_SYS_TIME_H
36 #include <sys/time.h>
37 #endif
38 
39 #ifdef HAVE_SYS_TYPES_H
40 #include <sys/types.h>
41 #endif
42 
43 #ifdef HAVE_UNISTD_H
44 #include <unistd.h>
45 #endif
46 
47 #define SAVE_CURLM_ERROR(__handle, __err) (__handle)->err.no = (int) __err;
48 
49 /* CurlMultiHandle class */
50 
51 zend_class_entry *curl_multi_ce;
52 
curl_multi_from_obj(zend_object * obj)53 static inline php_curlm *curl_multi_from_obj(zend_object *obj) {
54 	return (php_curlm *)((char *)(obj) - XtOffsetOf(php_curlm, std));
55 }
56 
57 #define Z_CURL_MULTI_P(zv) curl_multi_from_obj(Z_OBJ_P(zv))
58 
59 /* {{{ Returns a new cURL multi handle */
PHP_FUNCTION(curl_multi_init)60 PHP_FUNCTION(curl_multi_init)
61 {
62 	php_curlm *mh;
63 	CURLM *multi;
64 
65 	ZEND_PARSE_PARAMETERS_NONE();
66 	multi = curl_multi_init();
67 	if (UNEXPECTED(multi == NULL)) {
68 		zend_throw_error(NULL, "%s(): Could not initialize a new cURL multi handle", get_active_function_name());
69 		RETURN_THROWS();
70 	}
71 	object_init_ex(return_value, curl_multi_ce);
72 	mh = Z_CURL_MULTI_P(return_value);
73 	mh->multi = multi;
74 
75 	zend_llist_init(&mh->easyh, sizeof(zval), _php_curl_multi_cleanup_list, 0);
76 }
77 /* }}} */
78 
79 /* {{{ Add a normal cURL handle to a cURL multi handle */
PHP_FUNCTION(curl_multi_add_handle)80 PHP_FUNCTION(curl_multi_add_handle)
81 {
82 	zval      *z_mh;
83 	zval      *z_ch;
84 	php_curlm *mh;
85 	php_curl  *ch;
86 	CURLMcode error = CURLM_OK;
87 
88 	ZEND_PARSE_PARAMETERS_START(2,2)
89 		Z_PARAM_OBJECT_OF_CLASS(z_mh, curl_multi_ce)
90 		Z_PARAM_OBJECT_OF_CLASS(z_ch, curl_ce)
91 	ZEND_PARSE_PARAMETERS_END();
92 
93 	mh = Z_CURL_MULTI_P(z_mh);
94 	ch = Z_CURL_P(z_ch);
95 
96 	_php_curl_verify_handlers(ch, /* reporterror */ true);
97 
98 	_php_curl_cleanup_handle(ch);
99 
100 	Z_ADDREF_P(z_ch);
101 	zend_llist_add_element(&mh->easyh, z_ch);
102 
103 	error = curl_multi_add_handle(mh->multi, ch->cp);
104 	SAVE_CURLM_ERROR(mh, error);
105 
106 	RETURN_LONG((zend_long) error);
107 }
108 /* }}} */
109 
_php_curl_multi_cleanup_list(void * data)110 void _php_curl_multi_cleanup_list(void *data) /* {{{ */
111 {
112 	zval *z_ch = (zval *)data;
113 
114 	zval_ptr_dtor(z_ch);
115 }
116 /* }}} */
117 
118 /* Used internally as comparison routine passed to zend_list_del_element */
curl_compare_objects(zval * z1,zval * z2)119 static int curl_compare_objects( zval *z1, zval *z2 ) /* {{{ */
120 {
121 	return (Z_TYPE_P(z1) == Z_TYPE_P(z2) &&
122 			Z_TYPE_P(z1) == IS_OBJECT &&
123 			Z_OBJ_P(z1) == Z_OBJ_P(z2));
124 }
125 /* }}} */
126 
127 /* Used to find the php_curl resource for a given curl easy handle */
_php_curl_multi_find_easy_handle(php_curlm * mh,CURL * easy)128 static zval *_php_curl_multi_find_easy_handle(php_curlm *mh, CURL *easy) /* {{{ */
129 {
130 	php_curl 			*tmp_ch;
131 	zend_llist_position pos;
132 	zval				*pz_ch_temp;
133 
134 	for(pz_ch_temp = (zval *)zend_llist_get_first_ex(&mh->easyh, &pos); pz_ch_temp;
135 		pz_ch_temp = (zval *)zend_llist_get_next_ex(&mh->easyh, &pos)) {
136 		tmp_ch = Z_CURL_P(pz_ch_temp);
137 
138 		if (tmp_ch->cp == easy) {
139 			return pz_ch_temp;
140 		}
141 	}
142 
143 	return NULL;
144 }
145 /* }}} */
146 
147 /* {{{ Remove a multi handle from a set of cURL handles */
PHP_FUNCTION(curl_multi_remove_handle)148 PHP_FUNCTION(curl_multi_remove_handle)
149 {
150 	zval      *z_mh;
151 	zval      *z_ch;
152 	php_curlm *mh;
153 	php_curl  *ch;
154 	CURLMcode error = CURLM_OK;
155 
156 	ZEND_PARSE_PARAMETERS_START(2,2)
157 		Z_PARAM_OBJECT_OF_CLASS(z_mh, curl_multi_ce)
158 		Z_PARAM_OBJECT_OF_CLASS(z_ch, curl_ce)
159 	ZEND_PARSE_PARAMETERS_END();
160 
161 	mh = Z_CURL_MULTI_P(z_mh);
162 	ch = Z_CURL_P(z_ch);
163 
164 	error = curl_multi_remove_handle(mh->multi, ch->cp);
165 	SAVE_CURLM_ERROR(mh, error);
166 
167 	RETVAL_LONG((zend_long) error);
168 	zend_llist_del_element(&mh->easyh, z_ch, (int (*)(void *, void *))curl_compare_objects);
169 
170 }
171 /* }}} */
172 
173 /* {{{ Get all the sockets associated with the cURL extension, which can then be "selected" */
PHP_FUNCTION(curl_multi_select)174 PHP_FUNCTION(curl_multi_select)
175 {
176 	zval           *z_mh;
177 	php_curlm      *mh;
178 	double          timeout = 1.0;
179 	int             numfds = 0;
180 	CURLMcode error = CURLM_OK;
181 
182 	ZEND_PARSE_PARAMETERS_START(1,2)
183 		Z_PARAM_OBJECT_OF_CLASS(z_mh, curl_multi_ce)
184 		Z_PARAM_OPTIONAL
185 		Z_PARAM_DOUBLE(timeout)
186 	ZEND_PARSE_PARAMETERS_END();
187 
188 	mh = Z_CURL_MULTI_P(z_mh);
189 
190 	if (!(timeout >= 0.0 && timeout <= ((double)INT_MAX / 1000.0))) {
191 		php_error_docref(NULL, E_WARNING, "timeout must be between 0 and %d", (int)ceilf((double)INT_MAX / 1000));
192 #ifdef CURLM_BAD_FUNCTION_ARGUMENT
193 		SAVE_CURLM_ERROR(mh, CURLM_BAD_FUNCTION_ARGUMENT);
194 #endif
195 		RETURN_LONG(-1);
196 	}
197 
198 	error = curl_multi_wait(mh->multi, NULL, 0, (int) (timeout * 1000.0), &numfds);
199 	if (CURLM_OK != error) {
200 		SAVE_CURLM_ERROR(mh, error);
201 		RETURN_LONG(-1);
202 	}
203 
204 	RETURN_LONG(numfds);
205 }
206 /* }}} */
207 
208 /* {{{ Run the sub-connections of the current cURL handle */
PHP_FUNCTION(curl_multi_exec)209 PHP_FUNCTION(curl_multi_exec)
210 {
211 	zval      *z_mh;
212 	zval      *z_still_running;
213 	php_curlm *mh;
214 	int        still_running;
215 	CURLMcode error = CURLM_OK;
216 
217 	ZEND_PARSE_PARAMETERS_START(2, 2)
218 		Z_PARAM_OBJECT_OF_CLASS(z_mh, curl_multi_ce)
219 		Z_PARAM_ZVAL(z_still_running)
220 	ZEND_PARSE_PARAMETERS_END();
221 
222 	mh = Z_CURL_MULTI_P(z_mh);
223 
224 	{
225 		zend_llist_position pos;
226 		php_curl *ch;
227 		zval	*pz_ch;
228 
229 		for (pz_ch = (zval *)zend_llist_get_first_ex(&mh->easyh, &pos); pz_ch;
230 			pz_ch = (zval *)zend_llist_get_next_ex(&mh->easyh, &pos)) {
231 			ch = Z_CURL_P(pz_ch);
232 
233 			_php_curl_verify_handlers(ch, /* reporterror */ true);
234 		}
235 	}
236 
237 	still_running = zval_get_long(z_still_running);
238 	error = curl_multi_perform(mh->multi, &still_running);
239 	ZEND_TRY_ASSIGN_REF_LONG(z_still_running, still_running);
240 
241 	SAVE_CURLM_ERROR(mh, error);
242 	RETURN_LONG((zend_long) error);
243 }
244 /* }}} */
245 
246 /* {{{ Return the content of a cURL handle if CURLOPT_RETURNTRANSFER is set */
PHP_FUNCTION(curl_multi_getcontent)247 PHP_FUNCTION(curl_multi_getcontent)
248 {
249 	zval     *z_ch;
250 	php_curl *ch;
251 
252 	ZEND_PARSE_PARAMETERS_START(1, 1)
253 		Z_PARAM_OBJECT_OF_CLASS(z_ch, curl_ce)
254 	ZEND_PARSE_PARAMETERS_END();
255 
256 	ch = Z_CURL_P(z_ch);
257 
258 	if (ch->handlers.write->method == PHP_CURL_RETURN) {
259 		if (!ch->handlers.write->buf.s) {
260 			RETURN_EMPTY_STRING();
261 		}
262 		smart_str_0(&ch->handlers.write->buf);
263 		RETURN_STR_COPY(ch->handlers.write->buf.s);
264 	}
265 
266 	RETURN_NULL();
267 }
268 /* }}} */
269 
270 /* {{{ Get information about the current transfers */
PHP_FUNCTION(curl_multi_info_read)271 PHP_FUNCTION(curl_multi_info_read)
272 {
273 	zval      *z_mh;
274 	php_curlm *mh;
275 	CURLMsg	  *tmp_msg;
276 	int        queued_msgs;
277 	zval      *zmsgs_in_queue = NULL;
278 	php_curl  *ch;
279 
280 	ZEND_PARSE_PARAMETERS_START(1, 2)
281 		Z_PARAM_OBJECT_OF_CLASS(z_mh, curl_multi_ce)
282 		Z_PARAM_OPTIONAL
283 		Z_PARAM_ZVAL(zmsgs_in_queue)
284 	ZEND_PARSE_PARAMETERS_END();
285 
286 	mh = Z_CURL_MULTI_P(z_mh);
287 
288 	tmp_msg = curl_multi_info_read(mh->multi, &queued_msgs);
289 	if (tmp_msg == NULL) {
290 		RETURN_FALSE;
291 	}
292 
293 	if (zmsgs_in_queue) {
294 		ZEND_TRY_ASSIGN_REF_LONG(zmsgs_in_queue, queued_msgs);
295 	}
296 
297 	array_init(return_value);
298 	add_assoc_long(return_value, "msg", tmp_msg->msg);
299 	add_assoc_long(return_value, "result", tmp_msg->data.result);
300 
301 	/* find the original easy curl handle */
302 	{
303 		zval *pz_ch = _php_curl_multi_find_easy_handle(mh, tmp_msg->easy_handle);
304 		if (pz_ch != NULL) {
305 			/* we must save result to be able to read error message */
306 			ch = Z_CURL_P(pz_ch);
307 			SAVE_CURL_ERROR(ch, tmp_msg->data.result);
308 
309 			Z_ADDREF_P(pz_ch);
310 			add_assoc_zval(return_value, "handle", pz_ch);
311 		}
312 	}
313 }
314 /* }}} */
315 
316 /* {{{ Close a set of cURL handles */
PHP_FUNCTION(curl_multi_close)317 PHP_FUNCTION(curl_multi_close)
318 {
319 	php_curlm *mh;
320 	zval *z_mh;
321 
322 	zend_llist_position pos;
323 	zval *pz_ch;
324 
325 	ZEND_PARSE_PARAMETERS_START(1,1)
326 		Z_PARAM_OBJECT_OF_CLASS(z_mh, curl_multi_ce)
327 	ZEND_PARSE_PARAMETERS_END();
328 
329 	mh = Z_CURL_MULTI_P(z_mh);
330 
331 	for (pz_ch = (zval *)zend_llist_get_first_ex(&mh->easyh, &pos); pz_ch;
332 		pz_ch = (zval *)zend_llist_get_next_ex(&mh->easyh, &pos)) {
333 		php_curl *ch = Z_CURL_P(pz_ch);
334 		_php_curl_verify_handlers(ch, /* reporterror */ true);
335 		curl_multi_remove_handle(mh->multi, ch->cp);
336 	}
337 	zend_llist_clean(&mh->easyh);
338 }
339 /* }}} */
340 
341 /* {{{ Return an integer containing the last multi curl error number */
PHP_FUNCTION(curl_multi_errno)342 PHP_FUNCTION(curl_multi_errno)
343 {
344 	zval        *z_mh;
345 	php_curlm   *mh;
346 
347 	ZEND_PARSE_PARAMETERS_START(1,1)
348 		Z_PARAM_OBJECT_OF_CLASS(z_mh, curl_multi_ce)
349 	ZEND_PARSE_PARAMETERS_END();
350 
351 	mh = Z_CURL_MULTI_P(z_mh);
352 
353 	RETURN_LONG(mh->err.no);
354 }
355 /* }}} */
356 
357 /* {{{ return string describing error code */
PHP_FUNCTION(curl_multi_strerror)358 PHP_FUNCTION(curl_multi_strerror)
359 {
360 	zend_long code;
361 	const char *str;
362 
363 	ZEND_PARSE_PARAMETERS_START(1,1)
364 		Z_PARAM_LONG(code)
365 	ZEND_PARSE_PARAMETERS_END();
366 
367 	str = curl_multi_strerror(code);
368 	if (str) {
369 		RETURN_STRING(str);
370 	} else {
371 		RETURN_NULL();
372 	}
373 }
374 /* }}} */
375 
376 #if LIBCURL_VERSION_NUM >= 0x072C00 /* Available since 7.44.0 */
377 
_php_server_push_callback(CURL * parent_ch,CURL * easy,size_t num_headers,struct curl_pushheaders * push_headers,void * userp)378 static int _php_server_push_callback(CURL *parent_ch, CURL *easy, size_t num_headers, struct curl_pushheaders *push_headers, void *userp) /* {{{ */
379 {
380 	php_curl 				*ch;
381 	php_curl 				*parent;
382 	php_curlm 				*mh 			= (php_curlm *)userp;
383 	size_t 					rval 			= CURL_PUSH_DENY;
384 	php_curl_callback 		*t 				= mh->handlers.server_push;
385 	zval					*pz_parent_ch 	= NULL;
386 	zval 					pz_ch;
387 	zval 					headers;
388 	zval 					retval;
389 	char 					*header;
390 	zend_result				error;
391 	zend_fcall_info 		fci 			= empty_fcall_info;
392 
393 	pz_parent_ch = _php_curl_multi_find_easy_handle(mh, parent_ch);
394 	if (pz_parent_ch == NULL) {
395 		return rval;
396 	}
397 
398 	if (UNEXPECTED(zend_fcall_info_init(&t->func_name, 0, &fci, &t->fci_cache, NULL, NULL) == FAILURE)) {
399 		php_error_docref(NULL, E_WARNING, "Cannot call the CURLMOPT_PUSHFUNCTION");
400 		return rval;
401 	}
402 
403 	parent = Z_CURL_P(pz_parent_ch);
404 
405 	ch = init_curl_handle_into_zval(&pz_ch);
406 	ch->cp = easy;
407 	_php_setup_easy_copy_handlers(ch, parent);
408 
409 	size_t i;
410 	array_init(&headers);
411 	for(i=0; i<num_headers; i++) {
412 		header = curl_pushheader_bynum(push_headers, i);
413 		add_next_index_string(&headers, header);
414 	}
415 
416 	zend_fcall_info_argn(
417 		&fci, 3,
418 		pz_parent_ch,
419 		&pz_ch,
420 		&headers
421 	);
422 
423 	fci.retval = &retval;
424 
425 	error = zend_call_function(&fci, &t->fci_cache);
426 	zend_fcall_info_args_clear(&fci, 1);
427 	zval_ptr_dtor_nogc(&headers);
428 
429 	if (error == FAILURE) {
430 		php_error_docref(NULL, E_WARNING, "Cannot call the CURLMOPT_PUSHFUNCTION");
431 	} else if (!Z_ISUNDEF(retval)) {
432 		if (CURL_PUSH_DENY != zval_get_long(&retval)) {
433 		    rval = CURL_PUSH_OK;
434 			zend_llist_add_element(&mh->easyh, &pz_ch);
435 		} else {
436 			/* libcurl will free this easy handle, avoid double free */
437 			ch->cp = NULL;
438 		}
439 	}
440 
441 	return rval;
442 }
443 /* }}} */
444 
445 #endif
446 
_php_curl_multi_setopt(php_curlm * mh,zend_long option,zval * zvalue,zval * return_value)447 static bool _php_curl_multi_setopt(php_curlm *mh, zend_long option, zval *zvalue, zval *return_value) /* {{{ */
448 {
449 	CURLMcode error = CURLM_OK;
450 
451 	switch (option) {
452 		case CURLMOPT_PIPELINING:
453 		case CURLMOPT_MAXCONNECTS:
454 #if LIBCURL_VERSION_NUM >= 0x071e00 /* 7.30.0 */
455 		case CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE:
456 		case CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE:
457 		case CURLMOPT_MAX_HOST_CONNECTIONS:
458 		case CURLMOPT_MAX_PIPELINE_LENGTH:
459 		case CURLMOPT_MAX_TOTAL_CONNECTIONS:
460 #endif
461 #if LIBCURL_VERSION_NUM >= 0x074300 /* Available since 7.67.0 */
462 		case CURLMOPT_MAX_CONCURRENT_STREAMS:
463 #endif
464 		{
465 			zend_long lval = zval_get_long(zvalue);
466 
467 			if (option == CURLMOPT_PIPELINING && (lval & 1)) {
468 #if LIBCURL_VERSION_NUM >= 0x073e00 /* 7.62.0 */
469 				php_error_docref(NULL, E_WARNING, "CURLPIPE_HTTP1 is no longer supported");
470 #else
471 				php_error_docref(NULL, E_DEPRECATED, "CURLPIPE_HTTP1 is deprecated");
472 #endif
473 			}
474 			error = curl_multi_setopt(mh->multi, option, lval);
475 			break;
476 		}
477 #if LIBCURL_VERSION_NUM > 0x072D00 /* Available since 7.45.0 */
478 		case CURLMOPT_PUSHFUNCTION:
479 			if (mh->handlers.server_push == NULL) {
480 				mh->handlers.server_push = ecalloc(1, sizeof(php_curl_callback));
481 			} else if (!Z_ISUNDEF(mh->handlers.server_push->func_name)) {
482 				zval_ptr_dtor(&mh->handlers.server_push->func_name);
483 				mh->handlers.server_push->fci_cache = empty_fcall_info_cache;
484 			}
485 
486 			ZVAL_COPY(&mh->handlers.server_push->func_name, zvalue);
487 			error = curl_multi_setopt(mh->multi, CURLMOPT_PUSHFUNCTION, _php_server_push_callback);
488 			if (error != CURLM_OK) {
489 				return false;
490 			}
491 			error = curl_multi_setopt(mh->multi, CURLMOPT_PUSHDATA, mh);
492 			break;
493 #endif
494 		default:
495 			zend_argument_value_error(2, "is not a valid cURL multi option");
496 			error = CURLM_UNKNOWN_OPTION;
497 			break;
498 	}
499 
500 	SAVE_CURLM_ERROR(mh, error);
501 
502 	return error == CURLM_OK;
503 }
504 /* }}} */
505 
506 /* {{{ Set an option for the curl multi handle */
PHP_FUNCTION(curl_multi_setopt)507 PHP_FUNCTION(curl_multi_setopt)
508 {
509 	zval       *z_mh, *zvalue;
510 	zend_long        options;
511 	php_curlm *mh;
512 
513 	ZEND_PARSE_PARAMETERS_START(3,3)
514 		Z_PARAM_OBJECT_OF_CLASS(z_mh, curl_multi_ce)
515 		Z_PARAM_LONG(options)
516 		Z_PARAM_ZVAL(zvalue)
517 	ZEND_PARSE_PARAMETERS_END();
518 
519 	mh = Z_CURL_MULTI_P(z_mh);
520 
521 	if (_php_curl_multi_setopt(mh, options, zvalue, return_value)) {
522 		RETURN_TRUE;
523 	} else {
524 		RETURN_FALSE;
525 	}
526 }
527 /* }}} */
528 
529 /* CurlMultiHandle class */
530 
531 static zend_object_handlers curl_multi_handlers;
532 
curl_multi_create_object(zend_class_entry * class_type)533 static zend_object *curl_multi_create_object(zend_class_entry *class_type) {
534 	php_curlm *intern = zend_object_alloc(sizeof(php_curlm), class_type);
535 
536 	zend_object_std_init(&intern->std, class_type);
537 	object_properties_init(&intern->std, class_type);
538 	intern->std.handlers = &curl_multi_handlers;
539 
540 	return &intern->std;
541 }
542 
curl_multi_get_constructor(zend_object * object)543 static zend_function *curl_multi_get_constructor(zend_object *object) {
544 	zend_throw_error(NULL, "Cannot directly construct CurlMultiHandle, use curl_multi_init() instead");
545 	return NULL;
546 }
547 
curl_multi_free_obj(zend_object * object)548 void curl_multi_free_obj(zend_object *object)
549 {
550 	php_curlm *mh = curl_multi_from_obj(object);
551 
552 	zend_llist_position pos;
553 	php_curl *ch;
554 	zval	*pz_ch;
555 
556 	if (!mh->multi) {
557 		/* Can happen if constructor throws. */
558 		zend_object_std_dtor(&mh->std);
559 		return;
560 	}
561 
562 	for (pz_ch = (zval *)zend_llist_get_first_ex(&mh->easyh, &pos); pz_ch;
563 		pz_ch = (zval *)zend_llist_get_next_ex(&mh->easyh, &pos)) {
564 		if (!(OBJ_FLAGS(Z_OBJ_P(pz_ch)) & IS_OBJ_FREE_CALLED)) {
565 			ch = Z_CURL_P(pz_ch);
566 			_php_curl_verify_handlers(ch, /* reporterror */ false);
567 		}
568 	}
569 
570 	curl_multi_cleanup(mh->multi);
571 	zend_llist_clean(&mh->easyh);
572 	if (mh->handlers.server_push) {
573 		zval_ptr_dtor(&mh->handlers.server_push->func_name);
574 		efree(mh->handlers.server_push);
575 	}
576 
577 	zend_object_std_dtor(&mh->std);
578 }
579 
curl_multi_get_gc(zend_object * object,zval ** table,int * n)580 static HashTable *curl_multi_get_gc(zend_object *object, zval **table, int *n)
581 {
582 	php_curlm *curl_multi = curl_multi_from_obj(object);
583 
584 	zend_get_gc_buffer *gc_buffer = zend_get_gc_buffer_create();
585 
586 	if (curl_multi->handlers.server_push) {
587 		zend_get_gc_buffer_add_zval(gc_buffer, &curl_multi->handlers.server_push->func_name);
588 	}
589 
590 	zend_llist_position pos;
591 	for (zval *pz_ch = (zval *) zend_llist_get_first_ex(&curl_multi->easyh, &pos); pz_ch;
592 		pz_ch = (zval *) zend_llist_get_next_ex(&curl_multi->easyh, &pos)) {
593 		zend_get_gc_buffer_add_zval(gc_buffer, pz_ch);
594 	}
595 
596 	zend_get_gc_buffer_use(gc_buffer, table, n);
597 
598 	return zend_std_get_properties(object);
599 }
600 
curl_multi_register_handlers(void)601 void curl_multi_register_handlers(void) {
602 	curl_multi_ce->create_object = curl_multi_create_object;
603 
604 	memcpy(&curl_multi_handlers, &std_object_handlers, sizeof(zend_object_handlers));
605 	curl_multi_handlers.offset = XtOffsetOf(php_curlm, std);
606 	curl_multi_handlers.free_obj = curl_multi_free_obj;
607 	curl_multi_handlers.get_gc = curl_multi_get_gc;
608 	curl_multi_handlers.get_constructor = curl_multi_get_constructor;
609 	curl_multi_handlers.clone_obj = NULL;
610 	curl_multi_handlers.cast_object = curl_cast_object;
611 	curl_multi_handlers.compare = zend_objects_not_comparable;
612 }
613