为什么PHP不支持多线程? [英] Why does PHP not support multithreading?

查看:275
本文介绍了为什么PHP不支持多线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我到处都读到PHP不支持多线程,但是有解决方法.但是为什么 PHP不支持多线程?对于服务器端脚本语言,这似乎是一个明显的遗漏.

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.

推荐答案

几年后您可以将pthreads用于PHP多线程,但是您真的要这么做吗?

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

我不确定pthreads在许多托管环境中是否可用.坦率地说,我不急于找出答案.

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

对于许多应用程序来说,PHP的最大优势之一就是它的隔离性:一个过程,一个请求.通常,通过在请求期间对作业进行排队,然后在其他地方执行来完成多处理.例如,Laravel具有队列": https://laravel.com/docs/5.7/queues

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

由于PHP并不是在考虑多线程的情况下编写的,因此添加它将是一项巨大的工作(基本上是100%重写).

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

有人会说PHP几乎是一大堆: http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/.从这个角度来看,不包含线程也就不足为奇了.

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.

这篇关于为什么PHP不支持多线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆