Detailed instructions on using curl in php. The curl in php is a file I mentioned earlier. I will share with you my experiences on using phpcurl. I hope this will be helpful to you. I have mentioned this file before curl in php, which I have worked on in the past two days. next I will share with you my experiences in using php curl, I hope this will help you.
Curl is used for the work done in the past two days.
When the requested url is not on the same server, you cannot directly access it.
In this case, it is best to use curl. it is simple and convenient to simulate post requests.
Below is a record of the accumulation in the use process
The code is as follows: |
|
/* Remote post request */ Function getRemoteUrl ($ get_url ){ $ Curl = curl_init (); # Start a CURL session Curl_setopt ($ curl, CURLOPT_URL, $ get_url); # set a Url Curl_setopt ($ curl, CURLOPT_POST, true); # send a regular Post request Curl_setopt ($ curl, CURLOPT_TIMEOUT, 30); # set the timeout limit to prevent endless loops Curl_setopt ($ curl, CURLOPT_HEADER, 0); # display the returned Header area content Curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, 1); # The obtained information is returned as a file stream $ Return = curl_exec ($ curl); # perform the operation If (curl_errno ($ curl )){ Return false; } Curl_close ($ curl); # Close a CURL session Return $ return; } Function getCurlData ($ url ){ $ Curl = curl_init (); Curl_setopt ($ curl, CURLOPT_URL, $ url ); Curl_setopt ($ curl, CURLOPT_HEADER, false ); Curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, 1 ); Curl_setopt ($ curl, CURLOPT_TIMEOUT, 10 ); $ Result = curl_exec ($ curl ); Curl_close ($ curl ); Return $ result; } |
To sum up the curl method:
Initialize curl first
Use curl_setopt to set the target url and other options
Curl_exec: execute curl
Disable curl
The last step is output.
Curl () is highly efficient and supports multiple threads. However, you need to enable curl extension. The steps to enable curl extension are as follows:
1. copy the three php_curl.dll, libeay32.dll, and ssleay32.dll files in the PHP folder to system32;
2. remove the semicolon from php. ini (c: WINDOWS directory) and extension = php_curl.dll;
3. restart apache or IIS
I hope this will be helpful to you. Work done in the past two days...