search

Home  >  Q&A  >  body text

PHP is used as the background. When a web request comes, can it be processed using multiple processes or threads?

It is said that PHP does not support multi-process.
Is this scenario not suitable for PHP? If I want to update the information of a thousand data, upload a sql file, and then execute it one after another, it will definitely be very slow. Can I use pcntl_ related functions in the code to implement multi-process processing of this request?
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.

It is said that pcnt is invalid for http requests and is only applicable in cli mode. Could you please tell me, how should PHP handle this kind of scenario? Can it only be achieved by borrowing other languages?

为情所困为情所困2730 days ago660

reply all(4)I'll reply

  • 过去多啦不再A梦

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

    You can use queue or swoole

    reply
    0
  • 伊谢尔伦

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

    PHP can do concurrency with the help of extensions

    reply
    0
  • PHPz

    PHPz2017-06-05 11:11:26

    You can just do it in one process. . Only the backend has this need. . . One process is enough

    reply
    0
  • 習慣沉默

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

    It’s not that it’s not possible, it’s just a matter of whether you know how to do it. Swoole can do this, and the concurrency performance of using coroutines is very good. Although php is not the best language, it is also an underestimated language. Multi-threading is not necessarily good.

    reply
    0
  • Cancelreply