Curl_multi application in php multi-process

Source: Internet
Author: User
In php multi-process curl_multi applications, it is believed that many people have a headache for the curl_multi family of functions that are not detailed in the PHP Manual. they have few documents, and the examples are simple, so you cannot learn from them, I have also found many web pages and have not seen a complete application example.

  • Curl_multi_add_handle

  • Curl_multi_close

  • Curl_multi_exec

  • Curl_multi_getcontent

  • Curl_multi_info_read

  • Curl_multi_init

  • Curl_multi_remove_handle

  • Curl_multi_select

Generally, when you want to use these functions, it is obvious that you need to request multiple URLs at the same time, instead of one request in sequence. Otherwise, it is better to call curl_exec cyclically.

The steps are summarized as follows:

Step 1: Call curl_multi_init
Step 2: call curl_multi_add_handle cyclically
Note that the second parameter of curl_multi_add_handle is the sub-handle from curl_init.
Step 3: continuously call curl_multi_exec
Step 4: call curl_multi_getcontent cyclically to obtain the result as needed
Step 5: call curl_multi_remove_handle and call curl_close for each handle.
Step 6: call curl_multi_close

Here is a simple online search example by dirty (I will explain why dirty later ):

Curl_setopt ($ ch, CURLOPT_TIMEOUT, $ timeout );

Determine whether the request times out or other errors. use curl_error ($ conn [$ I]) before curl_multi_getcontent.

The above is the detailed content of the curl_multi application in php multi-process. For more information, see other related articles in the first PHP community!

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.