php做后台,一个web请求过来了,能否使用多进程或者多线程来处理?
为情所困
为情所困 2017-06-05 11:09:26
0
4
681

都说php不支持多进程,
那这种场景是不是就不适合php了?如果我要更新一千个数据的信息,上传一个sql文件,然后依次执行这样肯定会很慢,能否在代码里利用pcntl_相关的函数来实现多进程处理这个请求呢?
http://php.net/manual/zh/intr...

Process Control should not be enabled within a web server environment and unexpected results may happen if any Process Control functions are used within a web server environment.
At least for PHP 5.3.8 which I am using, and who knows how far back, it's not a matter of "should not", it's "can not". Even though I have compiled in PCNTL with --enable-pcntl, it turns out that it only compiles in to the CLI version of PHP, not the Apache module. As a result, I spent many hours trying to track down why function_exists('pcntl_fork') was returning false even though it compiled correctly. It turns out it returns true just fine from the CLI, and only returns false for HTTP requests. The same is true of ALL of the pcntl_*() functions.

这里面说pcnt对http请求无效,只适用再cli模式下,请问大神,php遇到这类场景,如何处理呢?难道就只能借用其他语言来实现么?

为情所困
为情所困

全部回复(4)
过去多啦不再A梦

可以使用队列或者swoole

伊谢尔伦

PHP可以借助扩展做并发

PHPzhong

你一个进程去做不就好了。。只有后台才有这种需求吧。。。一个进程足矣

習慣沉默

不是说不可以,只有你会不会的问题,swoole可以做这个,用协程并发性能很好,php虽然不是最好的语言,但也被低估的语言. 多线程不一定好.

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板