Web Hosting Talk







View Full Version : PHP multi-threaded


darmar
06-06-2007, 07:26 AM
Is it possible to build a multi-threaded application with PHP ?

I would appreciate for any links regarding this issue....


thank you

Jag
06-06-2007, 10:50 AM
Php itself doesn't support threading although you can run php in a threaded web server environment. Apache 2 supports multithreaded mode but the PHP Group doesn't recommend running PHP on Apache 2 in multithreaded mode.

You can do multi-process and use shared memory to pass data between processes. Here's an example of spawning a separate process:

http://www.experts-exchange.com/Web/Web_Languages/PHP/Q_20977409.html

You could extend this to fork multiple child processes.

mwatkins
06-06-2007, 11:03 AM
Perhaps you could share the general sort of application you are looking to build; that might spark some useful discussion on threading, or not to threading, that is the question.

crux_op
06-06-2007, 04:05 PM
Just an extension o what Jag said...

You can fake it.

I'd suggest using Fast-cgi with Lighttpd since Apache is unstable in multi-threaded mode.

Then you could maintain cross-thread communication through ram. PHP has a shared memory library, and there's always APC or Eacceleroator which lets you access memory as well as cache script opcode automatically.

darmar
06-06-2007, 05:53 PM
Perhaps you could share the general sort of application you are looking to build; that might spark some useful discussion on threading, or not to threading, that is the question.

well, at the moment I don't have any specific project to build with multi-threaded support, I would just like to know is it possible in PHP since I was doing some multi-threading in ASP.NET, but that's something completely different....


thanks to all, and I'll digg some info now that you said what to "look" for - Apache, Lighttpd......

mistwang
06-06-2007, 06:03 PM
PHP's thread support is weak, maybe python is a better choice if you want to go with multi-thread.

mwatkins
06-06-2007, 06:17 PM
If you don't have a specific requirement, I would ignore it. Even in Python, the use of threading isn't all that common although some projects use it extensively (see twisted).

Many web application servers intentionally use a forking model and are able to pump out high transaction rates. Avoiding threading greatly simplifies your debugging chores, as you probably know.