NYCPHP Meetup

NYPHP.org

[nycphp-talk] thread-safety analysis...

Hans Zaunere lists at zaunere.com
Sun Oct 22 10:53:16 EDT 2006


Hi Paul,

Paul Houle wrote on Saturday, October 21, 2006 10:29 PM:
> Hans Zaunere wrote:
> > 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.  
> > 
>     This is also a problem for Perl,  Python and many other languages
> which are advertised as thread-safe.  Java runtimes are threadsafe
> because of a general xenophobia:  the Java runtimes link in a limited
> number of C libraries,  and Java programmers don't really believe in
> linking in C libraries...  Though I have to admit that I've had good
> luck linking Java to Fortran.

Agreed; Java is threaded, from the ground up for the most part.

>     Lacking threads,  the big disadvantage of PHP is that it consumes
> more memory.  Data structures need to be replicated for each copy of
> PHP.  That said,  RAM is getting cheaper,  and PHP is parsimonious in
> it's memory use,  so most of us do just fine running PHP in processes
> instead of threads.

This I disagree with.  One of the primary reasons Java is built to be
threaded from the ground up is that it has to be.  I couldn't imagine having
a separate process instance of Java for every request - there isn't a server
on the planet with that much RAM - whereas PHP/Apache can happily live in
15-25mb of RAM or less.  Long story short, PHP is fair lighter than Java,
threads or no threads.

But there are certainly other advantages of threads, and I do hope that in
the near future core PHP configurations can begin to take advantage of them.
While creating threads in PHP isn't as important in my opinion for the
typical web application, being able to run in a thread-aware environment,
could be.

Unfortunately, this is a chicken and egg problem, since no one wants to put
the development time in until they see some justification... oh wait, I
covered this once already:

http://www.zend.com/zend/week/week217.php


---
Hans Zaunere / President / New York PHP
   www.nyphp.org  /  www.nyphp.com





More information about the talk mailing list