搜尋

首頁  >  問答  >  主體

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 天前688

全部回覆(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
  • 取消回覆