PHP多线程 [英] Php multithread
本文介绍了PHP多线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Php并不是真正用于多线程的,但是您有任何工作环境来处理php中的线程.
Php, isn't really made for multithread but do you have any workarround to deal with threads in php.
推荐答案
有几种解决方案,从嗯,差不多就可以解决"到露出眼睛".
There are a few solutions, varying from "Hmmm, just about OK" through to "Poke out your eyes".
- 将您的多线程代码编写为 PHP扩展.可能是最受支持的,但是您需要使用C(或扩展支持的另一种语言)编写.
- 将子进程生成到基础OS上,并使用标准文件句柄对其输入/输出进行读/写.请参阅 popen 中的一条路由,或 CURL 或类似的方式向自己发出其他HTTP请求,从而在Web服务器上搭载多处理能力.使您的所有代码像网络一样",但是冒着愤怒的支持开发人员跟踪您并使您断头的风险.
- Write your multithreaded code as a PHP extension. Probably the most supported, but you need to write in C (or another language supported for extensions).
- Spawn child processes onto the underlying OS, and read/write to their input/output with standard file handles. See popen for one route in, or PCNTL. Reasonable, and you can use PHP from the command line.
- Make other HTTP requests to yourself via CURL or similar, thus piggybacking on your web servers multi-processing capacity. Keeps all your code "web like", but runs the risk of irate support developers tracking you down and breaking thumbs.
这篇关于PHP多线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文