首页 >社区问答列表 >php做后台,一个web请求过来了,能否使用多进程或者多线程来处理?

php做后台,一个web请求过来了,能否使用多进程或者多线程来处理?

都说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遇到这类场景,如何处理呢?难道就只能借用其他语言来实现么?

  • 習慣沉默
  • 習慣沉默    2017-06-05 11:11:261楼

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

    +0添加回复

  • 回复