Why does PHP not support multithreading? [closed]

孤街浪徒 提交于 2019-12-01 06:32:41

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.

Read this URL i think it is help full to you.

PHP Multithreading – Faking It

http://w-shadow.com/blog/2007/08/20/php-multithreading-faking-it/

PHP doesn’t really support multi-threading per se but there are ways to do “fake” multithreading. Here’s one I saw in the PHPClasses.org newsletter –

Multi-thread Simulation.

Note that this class is intedend for use on a webserver, as opposed to running PHP scripts from a command line (or similar). Check the end of this post for some alternatives you can try if you’re using PHP as a stand-alone scripting language.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!