|
|
|
|
|
by jrockway
5998 days ago
|
|
Multithreading isn't at all appropriate for PHP and I can't think of a scenario where it would be needed. Not blocking the entire PHP process while waiting for database results, waiting for a file to download, waiting for memcached to respond, etc. I would (and do) use an event loop for this sort of things, but lightweight threads are technically a better abstraction. Web apps would use a lot less memory (and hardware) if people were not so afraid of threads. (This happens a lot; a bad implementation of something taints the whole category. pthreads, Java threads, Perl ithreads, etc., are broken, so all threading is bad. C++'s object model is bad, so all object oriented programming is bad. It's sad.) BTW: some good thread implementations include Haskell's and Perl's Coro. |
|
The thing is, I need those database results -- I can't do anything else until I have them. I received a single request from the user and I'm spitting out a single HTML response back. That's what PHP is all about. And mulithreading as optimization itself wouldn't improve performance because I'd be taking away CPU from other requests that are running concurrently.
> Web apps would use a lot less memory (and hardware) if people were not so afraid of threads.
Fundamentally I don't disagree; there's a lot of cool work going with event-based web servers. However, I think those designs are great for very specific tasks like chat servers and but require too much fiddling when doing traditional stateless web work. However, it may indeed be the future.