Notes for implementing multi-thread CURL in php

Source: Internet
Author: User
Php executes multiple threads in two ways: fscoket and curl. However, we often encounter that fscoket cannot be used, but many servers support curl. let's take a look at a multi-thread method using CURL, the PHP instance code is as follows: $... php executes multiple threads in two ways: fscoket and curl. However, we often encounter that fscoket cannot be used, but many servers support curl. let's take a look at a multi-thread method using CURL, the PHP instance code is as follows:

$ Ch = curl_init (); $ curl_opt = array (CURLOPT_URL => "http://www.phprm.com", CURLOPT_RETURNTRANSFER => 1, CURLOPT_TIMEOUT => 1); curl_setopt_array ($ ch, $ curl_opt ); curl_exec ($ ch); curl_close ($ ch );

The last article used the fscoket time asynchronous operation. in actual application, some servers cannot use it. in this case, curl is used to deal with it.

The first line:Initialize a curl resource

Row 2:Set the parameter array to be used

CURLOPT_URL

CURLOPT_RETURNTRANSFER

CURLOPT_TIMEOUT timeout. the minimum value here is 1 second, which is different from fscoket. here the code will wait for one minute. generally, code that takes a long time to execute will be executed asynchronously.

Row 3:Set parameters for the initialized resource and execute curl

Row 4:Disable curl resources

Now a curl asynchronous operation has been completed, but this is not recommended. we recommend that you use fscoket.

Permanent address:

Reprint at will ~ Please bring the tutorial URL ^

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.