xref: /php-src/ext/curl/multi.c (revision bb6dbdcf)
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 
PHP_FUNCTION(curl_multi_get_handles)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 
200 /* {{{ Get all the sockets associated with the cURL extension, which can then be "selected" */
PHP_FUNCTION(curl_multi_select)201 PHP_FUNCTION(curl_multi_select)
202 {
203 	zval           *z_mh;
204 	php_curlm      *mh;
205 	double          timeout = 1.0;
206 	int             numfds = 0;
207 	CURLMcode error = CURLM_OK;
208 
209 	ZEND_PARSE_PARAMETERS_START(1,2)
210 		Z_PARAM_OBJECT_OF_CLASS(z_mh, curl_multi_ce)
211 		Z_PARAM_OPTIONAL
212 		Z_PARAM_DOUBLE(timeout)
213 	ZEND_PARSE_PARAMETERS_END();
214 
215 	mh = Z_CURL_MULTI_P(z_mh);
216 
217 	if (!(timeout >= 0.0 && timeout <= (INT_MAX / 1000.0))) {
218 		zend_argument_value_error(2, "must be between 0 and %f", INT_MAX / 1000.0);
219 		RETURN_THROWS();
220 	}
221 
222 	error = curl_multi_wait(mh->multi, NULL, 0, (int) (timeout * 1000.0), &numfds);
223 	if (CURLM_OK != error) {
224 		SAVE_CURLM_ERROR(mh, error);
225 		RETURN_LONG(-1);
226 	}
227 
228 	RETURN_LONG(numfds);
229 }
230 /* }}} */
231 
232 /* {{{ Run the sub-connections of the current cURL handle */
PHP_FUNCTION(curl_multi_exec)233 PHP_FUNCTION(curl_multi_exec)
234 {
235 	zval      *z_mh;
236 	zval      *z_still_running;
237 	php_curlm *mh;
238 	int        still_running;
239 	CURLMcode error = CURLM_OK;
240 
241 	ZEND_PARSE_PARAMETERS_START(2, 2)
242 		Z_PARAM_OBJECT_OF_CLASS(z_mh, curl_multi_ce)
243 		Z_PARAM_ZVAL(z_still_running)
244 	ZEND_PARSE_PARAMETERS_END();
245 
246 	mh = Z_CURL_MULTI_P(z_mh);
247 
248 	{
249 		zend_llist_position pos;
250 		php_curl *ch;
251 		zval	*pz_ch;
252 
253 		for (pz_ch = (zval *)zend_llist_get_first_ex(&mh->easyh, &pos); pz_ch;
254 			pz_ch = (zval *)zend_llist_get_next_ex(&mh->easyh, &pos)) {
255 			ch = Z_CURL_P(pz_ch);
256 
257 			_php_curl_verify_handlers(ch, /* reporterror */ true);
258 		}
259 	}
260 
261 	still_running = zval_get_long(z_still_running);
262 	error = curl_multi_perform(mh->multi, &still_running);
263 	ZEND_TRY_ASSIGN_REF_LONG(z_still_running, still_running);
264 
265 	SAVE_CURLM_ERROR(mh, error);
266 	RETURN_LONG((zend_long) error);
267 }
268 /* }}} */
269 
270 /* {{{ Return the content of a cURL handle if CURLOPT_RETURNTRANSFER is set */
PHP_FUNCTION(curl_multi_getcontent)271 PHP_FUNCTION(curl_multi_getcontent)
272 {
273 	zval     *z_ch;
274 	php_curl *ch;
275 
276 	ZEND_PARSE_PARAMETERS_START(1, 1)
277 		Z_PARAM_OBJECT_OF_CLASS(z_ch, curl_ce)
278 	ZEND_PARSE_PARAMETERS_END();
279 
280 	ch = Z_CURL_P(z_ch);
281 
282 	if (ch->handlers.write->method == PHP_CURL_RETURN) {
283 		if (!ch->handlers.write->buf.s) {
284 			RETURN_EMPTY_STRING();
285 		}
286 		smart_str_0(&ch->handlers.write->buf);
287 		RETURN_STR_COPY(ch->handlers.write->buf.s);
288 	}
289 
290 	RETURN_NULL();
291 }
292 /* }}} */
293 
294 /* {{{ Get information about the current transfers */
PHP_FUNCTION(curl_multi_info_read)295 PHP_FUNCTION(curl_multi_info_read)
296 {
297 	zval      *z_mh;
298 	php_curlm *mh;
299 	CURLMsg	  *tmp_msg;
300 	int        queued_msgs;
301 	zval      *zmsgs_in_queue = NULL;
302 	php_curl  *ch;
303 
304 	ZEND_PARSE_PARAMETERS_START(1, 2)
305 		Z_PARAM_OBJECT_OF_CLASS(z_mh, curl_multi_ce)
306 		Z_PARAM_OPTIONAL
307 		Z_PARAM_ZVAL(zmsgs_in_queue)
308 	ZEND_PARSE_PARAMETERS_END();
309 
310 	mh = Z_CURL_MULTI_P(z_mh);
311 
312 	tmp_msg = curl_multi_info_read(mh->multi, &queued_msgs);
313 	if (tmp_msg == NULL) {
314 		RETURN_FALSE;
315 	}
316 
317 	if (zmsgs_in_queue) {
318 		ZEND_TRY_ASSIGN_REF_LONG(zmsgs_in_queue, queued_msgs);
319 	}
320 
321 	array_init(return_value);
322 	add_assoc_long(return_value, "msg", tmp_msg->msg);
323 	add_assoc_long(return_value, "result", tmp_msg->data.result);
324 
325 	/* find the original easy curl handle */
326 	{
327 		zval *pz_ch = _php_curl_multi_find_easy_handle(mh, tmp_msg->easy_handle);
328 		if (pz_ch != NULL) {
329 			/* we must save result to be able to read error message */
330 			ch = Z_CURL_P(pz_ch);
331 			SAVE_CURL_ERROR(ch, tmp_msg->data.result);
332 
333 			Z_ADDREF_P(pz_ch);
334 			add_assoc_zval(return_value, "handle", pz_ch);
335 		}
336 	}
337 }
338 /* }}} */
339 
340 /* {{{ Close a set of cURL handles */
PHP_FUNCTION(curl_multi_close)341 PHP_FUNCTION(curl_multi_close)
342 {
343 	php_curlm *mh;
344 	zval *z_mh;
345 
346 	zend_llist_position pos;
347 	zval *pz_ch;
348 
349 	ZEND_PARSE_PARAMETERS_START(1,1)
350 		Z_PARAM_OBJECT_OF_CLASS(z_mh, curl_multi_ce)
351 	ZEND_PARSE_PARAMETERS_END();
352 
353 	mh = Z_CURL_MULTI_P(z_mh);
354 
355 	for (pz_ch = (zval *)zend_llist_get_first_ex(&mh->easyh, &pos); pz_ch;
356 		pz_ch = (zval *)zend_llist_get_next_ex(&mh->easyh, &pos)) {
357 		php_curl *ch = Z_CURL_P(pz_ch);
358 		_php_curl_verify_handlers(ch, /* reporterror */ true);
359 		curl_multi_remove_handle(mh->multi, ch->cp);
360 	}
361 	zend_llist_clean(&mh->easyh);
362 }
363 /* }}} */
364 
365 /* {{{ Return an integer containing the last multi curl error number */
PHP_FUNCTION(curl_multi_errno)366 PHP_FUNCTION(curl_multi_errno)
367 {
368 	zval        *z_mh;
369 	php_curlm   *mh;
370 
371 	ZEND_PARSE_PARAMETERS_START(1,1)
372 		Z_PARAM_OBJECT_OF_CLASS(z_mh, curl_multi_ce)
373 	ZEND_PARSE_PARAMETERS_END();
374 
375 	mh = Z_CURL_MULTI_P(z_mh);
376 
377 	RETURN_LONG(mh->err.no);
378 }
379 /* }}} */
380 
381 /* {{{ return string describing error code */
PHP_FUNCTION(curl_multi_strerror)382 PHP_FUNCTION(curl_multi_strerror)
383 {
384 	zend_long code;
385 	const char *str;
386 
387 	ZEND_PARSE_PARAMETERS_START(1,1)
388 		Z_PARAM_LONG(code)
389 	ZEND_PARSE_PARAMETERS_END();
390 
391 	str = curl_multi_strerror(code);
392 	if (str) {
393 		RETURN_STRING(str);
394 	} else {
395 		RETURN_NULL();
396 	}
397 }
398 /* }}} */
399 
400 
_php_server_push_callback(CURL * parent_ch,CURL * easy,size_t num_headers,struct curl_pushheaders * push_headers,void * userp)401 static int _php_server_push_callback(CURL *parent_ch, CURL *easy, size_t num_headers, struct curl_pushheaders *push_headers, void *userp) /* {{{ */
402 {
403 	php_curl 				*ch;
404 	php_curl 				*parent;
405 	php_curlm 				*mh 			= (php_curlm *)userp;
406 	size_t 					rval 			= CURL_PUSH_DENY;
407 	zval					*pz_parent_ch 	= NULL;
408 	zval 					pz_ch;
409 	zval 					headers;
410 	zval 					retval;
411 
412 	pz_parent_ch = _php_curl_multi_find_easy_handle(mh, parent_ch);
413 	if (pz_parent_ch == NULL) {
414 		return rval;
415 	}
416 
417 	parent = Z_CURL_P(pz_parent_ch);
418 
419 	ch = init_curl_handle_into_zval(&pz_ch);
420 	ch->cp = easy;
421 	_php_setup_easy_copy_handlers(ch, parent);
422 
423 	array_init(&headers);
424 	for (size_t i = 0; i < num_headers; i++) {
425 		char *header = curl_pushheader_bynum(push_headers, i);
426 		add_next_index_string(&headers, header);
427 	}
428 
429 	ZEND_ASSERT(pz_parent_ch);
430 	zval call_args[3] = {*pz_parent_ch, pz_ch, headers};
431 
432 	zend_call_known_fcc(&mh->handlers.server_push, &retval, /* param_count */ 3, call_args, /* named_params */ NULL);
433 	zval_ptr_dtor_nogc(&headers);
434 
435 	if (!Z_ISUNDEF(retval)) {
436 		if (CURL_PUSH_DENY != zval_get_long(&retval)) {
437 		    rval = CURL_PUSH_OK;
438 			zend_llist_add_element(&mh->easyh, &pz_ch);
439 		} else {
440 			/* libcurl will free this easy handle, avoid double free */
441 			ch->cp = NULL;
442 		}
443 	}
444 
445 	return rval;
446 }
447 /* }}} */
448 
_php_curl_multi_setopt(php_curlm * mh,zend_long option,zval * zvalue,zval * return_value)449 static bool _php_curl_multi_setopt(php_curlm *mh, zend_long option, zval *zvalue, zval *return_value) /* {{{ */
450 {
451 	CURLMcode error = CURLM_OK;
452 
453 	switch (option) {
454 		case CURLMOPT_PIPELINING:
455 		case CURLMOPT_MAXCONNECTS:
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 #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 /* Available since 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 		case CURLMOPT_PUSHFUNCTION: {
478 			/* See php_curl_set_callable_handler */
479 			if (ZEND_FCC_INITIALIZED(mh->handlers.server_push)) {
480 				zend_fcc_dtor(&mh->handlers.server_push);
481 			}
482 
483 			char *error_str = NULL;
484 			if (UNEXPECTED(!zend_is_callable_ex(zvalue, /* object */ NULL, /* check_flags */ 0, /* callable_name */ NULL, &mh->handlers.server_push, /* error */ &error_str))) {
485 				if (!EG(exception)) {
486 					zend_argument_type_error(2, "must be a valid callback for option CURLMOPT_PUSHFUNCTION, %s", error_str);
487 				}
488 				efree(error_str);
489 				return false;
490 			}
491 			zend_fcc_addref(&mh->handlers.server_push);
492 
493 			error = curl_multi_setopt(mh->multi, CURLMOPT_PUSHFUNCTION, _php_server_push_callback);
494 			if (error != CURLM_OK) {
495 				return false;
496 			}
497 			error = curl_multi_setopt(mh->multi, CURLMOPT_PUSHDATA, mh);
498 			break;
499 		}
500 		default:
501 			zend_argument_value_error(2, "is not a valid cURL multi option");
502 			error = CURLM_UNKNOWN_OPTION;
503 			break;
504 	}
505 
506 	SAVE_CURLM_ERROR(mh, error);
507 
508 	return error == CURLM_OK;
509 }
510 /* }}} */
511 
512 /* {{{ Set an option for the curl multi handle */
PHP_FUNCTION(curl_multi_setopt)513 PHP_FUNCTION(curl_multi_setopt)
514 {
515 	zval       *z_mh, *zvalue;
516 	zend_long        options;
517 	php_curlm *mh;
518 
519 	ZEND_PARSE_PARAMETERS_START(3,3)
520 		Z_PARAM_OBJECT_OF_CLASS(z_mh, curl_multi_ce)
521 		Z_PARAM_LONG(options)
522 		Z_PARAM_ZVAL(zvalue)
523 	ZEND_PARSE_PARAMETERS_END();
524 
525 	mh = Z_CURL_MULTI_P(z_mh);
526 
527 	if (_php_curl_multi_setopt(mh, options, zvalue, return_value)) {
528 		RETURN_TRUE;
529 	} else {
530 		RETURN_FALSE;
531 	}
532 }
533 /* }}} */
534 
535 /* CurlMultiHandle class */
536 
curl_multi_create_object(zend_class_entry * class_type)537 static zend_object *curl_multi_create_object(zend_class_entry *class_type) {
538 	php_curlm *intern = zend_object_alloc(sizeof(php_curlm), class_type);
539 
540 	zend_object_std_init(&intern->std, class_type);
541 	object_properties_init(&intern->std, class_type);
542 
543 	return &intern->std;
544 }
545 
curl_multi_get_constructor(zend_object * object)546 static zend_function *curl_multi_get_constructor(zend_object *object) {
547 	zend_throw_error(NULL, "Cannot directly construct CurlMultiHandle, use curl_multi_init() instead");
548 	return NULL;
549 }
550 
curl_multi_free_obj(zend_object * object)551 static void curl_multi_free_obj(zend_object *object)
552 {
553 	php_curlm *mh = curl_multi_from_obj(object);
554 
555 	zend_llist_position pos;
556 	php_curl *ch;
557 	zval	*pz_ch;
558 
559 	if (!mh->multi) {
560 		/* Can happen if constructor throws. */
561 		zend_object_std_dtor(&mh->std);
562 		return;
563 	}
564 
565 	for (pz_ch = (zval *)zend_llist_get_first_ex(&mh->easyh, &pos); pz_ch;
566 		pz_ch = (zval *)zend_llist_get_next_ex(&mh->easyh, &pos)) {
567 		if (!(OBJ_FLAGS(Z_OBJ_P(pz_ch)) & IS_OBJ_FREE_CALLED)) {
568 			ch = Z_CURL_P(pz_ch);
569 			_php_curl_verify_handlers(ch, /* reporterror */ false);
570 		}
571 	}
572 
573 	curl_multi_cleanup(mh->multi);
574 	zend_llist_clean(&mh->easyh);
575 
576 	if (ZEND_FCC_INITIALIZED(mh->handlers.server_push)) {
577 		zend_fcc_dtor(&mh->handlers.server_push);
578 	}
579 
580 	zend_object_std_dtor(&mh->std);
581 }
582 
curl_multi_get_gc(zend_object * object,zval ** table,int * n)583 static HashTable *curl_multi_get_gc(zend_object *object, zval **table, int *n)
584 {
585 	php_curlm *curl_multi = curl_multi_from_obj(object);
586 
587 	zend_get_gc_buffer *gc_buffer = zend_get_gc_buffer_create();
588 
589 	if (ZEND_FCC_INITIALIZED(curl_multi->handlers.server_push)) {
590 		zend_get_gc_buffer_add_fcc(gc_buffer, &curl_multi->handlers.server_push);
591 	}
592 
593 	zend_llist_position pos;
594 	for (zval *pz_ch = (zval *) zend_llist_get_first_ex(&curl_multi->easyh, &pos); pz_ch;
595 		pz_ch = (zval *) zend_llist_get_next_ex(&curl_multi->easyh, &pos)) {
596 		zend_get_gc_buffer_add_zval(gc_buffer, pz_ch);
597 	}
598 
599 	zend_get_gc_buffer_use(gc_buffer, table, n);
600 
601 	return zend_std_get_properties(object);
602 }
603 
604 static zend_object_handlers curl_multi_handlers;
605 
curl_multi_register_handlers(void)606 void curl_multi_register_handlers(void) {
607 	curl_multi_ce->create_object = curl_multi_create_object;
608 	curl_multi_ce->default_object_handlers = &curl_multi_handlers;
609 
610 	memcpy(&curl_multi_handlers, &std_object_handlers, sizeof(zend_object_handlers));
611 	curl_multi_handlers.offset = XtOffsetOf(php_curlm, std);
612 	curl_multi_handlers.free_obj = curl_multi_free_obj;
613 	curl_multi_handlers.get_gc = curl_multi_get_gc;
614 	curl_multi_handlers.get_constructor = curl_multi_get_constructor;
615 	curl_multi_handlers.clone_obj = NULL;
616 	curl_multi_handlers.cast_object = curl_cast_object;
617 	curl_multi_handlers.compare = zend_objects_not_comparable;
618 }
619