What does the PHP server use to implement multi-process?

Source: Internet
Author: User
The php backend will return a large amount of data from other places and present it in arrays. The data needs to be written to the database one by one. The single process is too slow, I want to use multiple processes for implementation. I checked some information and noticed the pcntl _ * series functions, but it seems that this is only available in the command line... the php backend will return a large amount of data from other places and present it in arrays. The data needs to be written to the database one by one. The single process is too slow, I want to use multiple processes for implementation.
I checked some information and noticed the pcntl _ ** series of functions, but it seems that they can only be executed in the command line and cannot be used on the server.
Is there any way to achieve this?

Please kindly advise!

Reply content:

The php backend will return a large amount of data from other places and present it in arrays. The data needs to be written to the database one by one. The single process is too slow, I want to use multiple processes for implementation.
I checked some information and noticed the pcntl _ ** series of functions, but it seems that they can only be executed in the command line and cannot be used on the server.
Is there any way to achieve this?

Please kindly advise!

What you need is not a multi-process, but a message queue.

After receiving the request, the web server pushes a message to the message queue and then returns the browser result (for example, displaying the message in progress)

In addition, a script for consuming a message queue is run for a long time. it obtains the message from the message queue for processing, and changes the status to complete processing (if you have the concept of a task)

At this level, you need multi-process or multi-thread depending on your specific situation, multi-process or multi-thread operations can only improve IO-intensive operations (from the perspective that you need to request a large amount of data elsewhere)

Meet you: look at the pcntl_fork function.

Php_swoole is more mature and stable than pcntl. In addition, the message queue must be used for better processing.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.