[nycphp-talk] thread-safety analysis...
lists at zaunere.com
Sat Oct 21 10:04:20 EDT 2006
Vugranam Sreedhar wrote on Saturday, October 21, 2006 6:39 AM:
> I have studying thread-safety issue with PHP and Apache2. I know PHP
> does not have a thread model (like Java). I cannot seem to find real
> that clearly explains the problem. I am looking at building tool that
> will scan PHP code and tell me whether it is thread-safe or not.
> Would anyone be interested in such a tool ;-)
Others on this list can perhaps provide more detail, but here's a run
PHP cannot do threading itself - it can only fork(). However, PHP's core
itself can be compiled to run in a threaded environment (for instance under
Apache 2's various MPMs). So PHP itself isn't creating threads - Apache is
handling user requests in a threaded manner, which in turn makes PHP run in
a threaded way.
The problem really is not thread safe code written in the PHP language, but
rather the environment in which PHP runs in. Now PHP can be compiled for
thread safety (TSRM, for instance http://us2.php.net/tsrm). However,
because PHP is often linked against so many external libraries
(gd/jpeg/xml/etc) it cannot be considered safe to execute in a threaded
environment. This is the real problem and one of PHP's greatest strengths
and unfortunate faults.
So, writing an application that scans PHP code for thread safety wouldn't be
useful. However, writing an application that would scan the C code of the
libraries used in PHP's extensions, would be of great value - then we could
determine which PHP configuration combinations are thread safe, and which
are not. For instance, I had once run PHP only with the MySQL and Oracle
extensions compiled, under Apache 2 with threading - it was stable for
years. Rasmus had once started to document which libraries were thread safe
and which were not, but I think it hasn't been actively maintained.
Hopefully this somewhat clarifies a confusing issue.
Hans Zaunere / President / New York PHP
www.nyphp.org / www.nyphp.com
More information about the talk