This is interesting Shane and I started talking about php threads at OSCON.
But baiscally your soulition won't work. I can't remember the specfic reason. I think i tried the same thing along time ago. If it were that simple it probally would have been done already :). For threading php you will need to have each php thread have a seprate interperter. So then you would need some way to share variables between php interperters ($_SHARED[] possibly). The $_SHARED (or equiv) would need read/write locks around the access to the variable. Shane and a few other hashed some ideas at the confrence and with stealing some ideas from perl we came up with a decent soulition. You might want to get ahold of him and see what he is going to do with it. -brad --- Alan Knowles <[EMAIL PROTECTED]> wrote: > Im looking at adding threading to php, (for the cgi/cli stuff).. > > The story so far: > > I've created an extension which diverts all zend_execute calls into the > extension -> phpthreads_execute. > this function is a copy of zend_execute with a few modifications > - to copy & restore things like EG(active_symbol_table); > - to malloc lock and unlock the execute loop and release on each opcode. > > I've started testing the phpthreads_create($callback); - it appears to > work ok, execept it segfaults on completion.. - trying to reduce > refcounts somewhere. > > The fireup code looks something like this.. > > void phpthreads_create(void *ptr) { > zval myretval; > zval *callback = (zval *) ptr; > > if (!call_user_function( EG(function_table), NULL, callback, > &myretval, 0, NULL TSRMLS_CC )) { > zend_error(E_ERROR, "Problem Starting thread with > callback"); > } > > pthread_exit(NULL); > > > } > /* {{{ proto string phpthreads_thread(string function) > Return a string to confirm that the module is compiled in */ > PHP_FUNCTION(phpthreads_create) > { > > zval *callback; > pthread_t thread; > > if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", > &callback) == FAILURE) { > return; > } > pthread_create( &thread, NULL, (void *) phpthreads_create, > (void*) callback); > RETURN_TRUE; > } > > and the backtrace of the simple threaded test looks like this.. > 0x08128f08 in _zval_ptr_dtor (zval_ptr=0x81b5ce8) at > /usr/src/php/php4/Zend/zend_execute_API.c:275 > 275 (*zval_ptr)->refcount--; > (gdb) bt > #0 0x08128f08 in _zval_ptr_dtor (zval_ptr=0x81b5ce8) at > /usr/src/php/php4/Zend/zend_execute_API.c:275 > #1 0x424ceba2 in ?? () > #2 0x424c7c92 in ?? () > #3 0x08130588 in zend_execute_scripts (type=8, retval=0x0, > file_count=3) at /usr/src/php/php4/Zend/zend.c:810 > #4 0x08110abd in php_execute_script (primary_file=0x40006c71) at > /usr/src/php/php4/main/main.c:1398 > #5 0x08110138 in php_module_shutdown () at > /usr/src/php/php4/main/main.c:1058 > #6 0x2e325f43 in ?? () > > does anyone want to suggest what might be missing - is it worth putting > this into pecl - and does someone what to lend a hand?? > > regards > alan > > > > > > > -- > PHP Development Mailing List <http://www.php.net/> > To unsubscribe, visit: http://www.php.net/unsub.php > __________________________________________________ Do You Yahoo!? Yahoo! Health - Feel better, live better http://health.yahoo.com -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php