Question

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.

Was it helpful?

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top