Hi Topi,

I've recently been dealing with some threading issues with PHP/ZE.
PHP keeps state in thread-local variables which are a implemented
as a globally visible table, indexed by a thread identifier.

All thread-safe PHP and Zend API functions pass around a pointer
to the thread local storage in the form of a variable called tsrm_ls
which is initially obtained by the macro TSRMLS_FETCH().  Once
obtained it is passed through to all the API functions that are
thread safety aware.  PHP uses macros like PG() to refer to particular
"global" structures contained in a table with the tsrm_ls.

It is possible to override tsrm_ls with some other value, effective
granting a different thread access to the engine state of another thread.
However, this is definitely NOT supported, because not all the possible
API functions receive the TSRM variables in their parameters, which
means that they will then perform a TSRMLS_FETCH() on their own:
something that will end up with the ZE bailing out in the foreign thread.

So, the short answer is that it is not possible to use threading
on the scripting level in PHP, and won't be possible to implement
without making major changes to ZE and PHP.

--Wez. 

On 20/05/02, "Topi Maenpaa" <[EMAIL PROTECTED]> wrote:
> Hi,
> 
> I've just started implementing a pthread extension to the PHP language.
> Things just aren't as simple as I expected. I have no problems in creating
> threads, mutexes and the like. But it seems that zend_execute and companion
> functions use some global variables (executor globals, accessed via EG,
> etc.) that are naturally shared with all threads that I create. This
> obviously causes serious problems. My question is: how does the zend engine
> internally handle threading? I know there is some kind of mutex mechanism
> because Apache uses multiple threads instead of processed to handle client
> requests. Without documentation, it is very hard to figure out how things
> are done. If I was able to use the same threading mechanism within a
> script, the extension would be more portable, too (afaik, pthreads work
> only on unices...) All comments are welcome.
> 
> -Topi-
>  << http://ee.oulu.fi/~topiolli >>
> 
> 
> -- 
> PHP Development Mailing List <http://www.php.net/>
> To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to