Hi, On Tue, 2009-07-14 at 19:28 +0200, Thomas Koch wrote: > So I'm happy for anybody interested to look over my work and help me to > become > better: > http://github.com/thkoch2001/gearman-php-worker/tree/master
You are wrapping every call inside PHP_EMBED_START_BLOCK/_END_BLOCK calls. By this you have a full PHP startup and shutdown on every single request to the worker. This costs quite some time and that startup/shutdown is not thread-safe which means multiple threads starting and finishing PHP will end with quite some trouble. For doing this you should write your own SAPI, for that take the sapi structure and create the helper functions (for a start take them from php_embed.c). In your main you then do the following (pseudo-code) void main() { /* param parsing and stuff ... */ tsrm_startup(1, 1, 0, NULL); sapi_startup(&gearman_module); /* now PHP is ready to handle requests */ startWorkers( host, port, scripts_list, numberOfWorkers ); /* after the last request finished and while shutting down: / php_module_shutdown(TSRMLS_C); sapi_shutdown(); tsrm_shutdown(); } and then in your runPHP it looks, using shortened and pseudo-code, like this: char *runPHP( char *scriptName ) { void ***tsrm_ls = NULL; tsrm_ls = ts_resource(0); /* actually you would do this when creating the thread and pass the TSRMLS macros along*/ if (php_request_startup(TSRMLS_C)==FAILURE) { return NULL; } /* prepare script handle and environment */ zend_try_first { php_execute_script(&scriptHandle TSRMLS_CC); } zend_catch { /* handle error */ } zend_end_try(); php_request_shutdown((void *) 0); } That's not tested and based on my mind and quick checking of my code, not the perfect final implementation but hopefully a good start. Please double check with the implementation of other SAPIs! For making development simple you might link such code against the embed sapi (and ignore php_embed.[ch]) at least the plumbing code should be moved into php-src/sapi/gearman or something and properly built without embed dependency. johannes -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php