PHP Extension: call_user_function from a pthread returns error -
i working on php extension. php extension should make use of multithreading via pthreads. inside thread function in php userspace should called via call_user_function
. php configured --enable-maintainer-zts
config option.
i have written code calls php function in user space works expected. see following code snippets minimal working example:
extension code (in c)
php_function(hello_world) { startworker(); return_null(); } void *startworker() { static zval retval; zval function_name; init_zval(function_name); zval_string(&function_name, "hello", 1); tsrmls_fetch(); if (call_user_function(cg(function_table), null, &function_name, &retval, 0, null tsrmls_cc) == success) { printf("successfully called function\n"); } else { printf("calling user function returned error\n"); } zval_dtor(&function_name); }
php code:
<?php function hello() { echo "php hello() called\n"; } hello_world();
if call php code, returns following output - expected.
php hello() called called function
but want call php function new thread. modify extension code follows:
php_function(hello_world) { pthread_t thread; pthread_create( &thread, null, &startworker, null); pthread_join(thread, null); return_null(); }
but now, of sudden, calling php code results in following output:
calling user function returned error
i track down source of error following if statement in zend_call_function, have no idea why eg(active)
false @ point how can prevent this:
if (!eg(active)) { return failure; /* executor inactive */ }
so questions are:
- is possible call php userspace functions inside threads?
- if so, why
call_user_function
return error? - what eg(active) mean? how can make evaluate true inside pthread?
any hints on highly appreciated.
Comments
Post a Comment