搜索

首页  >  问答  >  正文

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

为情所困为情所困2763 天前686

全部回复(4)我来回复

  • 过去多啦不再A梦

    过去多啦不再A梦2017-06-05 11:11:26

    可以使用队列或者swoole

    回复
    0
  • 伊谢尔伦

    伊谢尔伦2017-06-05 11:11:26

    PHP可以借助扩展做并发

    回复
    0
  • PHPz

    PHPz2017-06-05 11:11:26

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

    回复
    0
  • 習慣沉默

    習慣沉默2017-06-05 11:11:26

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

    回复
    0
  • 取消回复