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