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 ^