How do you store callables(callbacks)?

From: Date: Fri, 20 Nov 2015 16:00:56 +0000
Subject: How do you store callables(callbacks)?
Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-13337@lists.php.net to get a copy of this message
Hi, I'm looking for a reliable way to store user callbacks. Of course, the simplest way is to store zval itself, then call_user_function(). But this approach ignores caching (zend_fcall_info_cache), so performance probably will suffer in case of frequent callback calls. One option is to store zend_fcall_info and zend_fcall_info_cache: struct php_myext_func { zend_fcall_info fci; zend_fcall_info_cache fcc; } Then zend_call_function(). This implies keeping fci zvals alive by incrementing refcount when necessary. I can't find a Zend API function for doing this, by the way. Another option is to store just required members of zend_fcall_info: struct php_myext_func { zend_function *func_ptr; zend_class_entry *ce; zval obj; zval closure; }; (https://github.com/php/php-src/blob/master/ext/spl/php_spl.c#L388) This still requires manual incrementing and decrementing the refcounts. With these we can use zend_call_method(). By the way, it fails with SIGSEGV here: ZVAL_STRINGL(&fci.function_name, function_name, function_name_len); I don't like both approaches - they look unreliable, I'm not sure I haven't missed something. -- Ruslan Osmanov

Attachment: [application/pgp-signature] signature.asc
« previous php.pecl.dev (#13337) next »