Search code examples
phpmultithreadinglanguage-design

Why does PHP not support multithreading?


I've read everywhere that PHP does not support multithreading but there are workarounds. But why does PHP not support multithreading? For a server-side scripting language, that seems like a glaring omission.


Solution

  • Edit several years later: you can use pthreads for PHP multithreading, but do you really want to?

    I'm not sure if pthreads is available on many hosting environments. And frankly I am not in a rush to find out.

    One of PHP's biggest strengths for many applications is its isolation: one process, one request. Multi-processing is usually done by queuing a job during a request and executing it somewhere else. For example, Laravel has "queues": https://laravel.com/docs/5.7/queues


    Because PHP was not written with multithreading in mind and it would be a huge effort (basically a 100% rewrite) to add it in.

    Some would say that PHP is pretty much a gigantic pile: http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/. From that perspective it is not surprising that threading is not included.