We knew before. The PHP curl_exec function is one of the PHP Curl function lists, and its function is to perform a curl session. After performing a curl session, we're going to get the information about the curl we're performing, and we'll output the information, but how do we do it? This article will show you how to request information about the output of the curl request.
After the curl_exec () function executes, you can use the Curl_getinfo () function to get information about the Curl request output
Curl_getinfo is the information that gets a curl connection resource handle
His grammar.
Mixed Curl_getinfo (Resource $ch [, int $opt = 0])
Gets information about the last transmission.
Parameters
Ch
The curl handle returned by Curl_init ().
Opt
This parameter may be one of the following constants:
Curlinfo_effective_url-The last valid URL address
Curlinfo_http_code-The last HTTP code received
Curlinfo_filetime-the time that the document was retrieved remotely, and the return value is "1" if it cannot be obtained
Curlinfo_total_time-time spent on the last transmission
Curlinfo_namelookup_time-time consumed by name resolution
Curlinfo_connect_time-time spent establishing a connection
Curlinfo_pretransfer_time-the time to use from establishing a connection to preparing the transfer
Curlinfo_starttransfer_time-The time it takes to start a connection to a transfer
Curlinfo_redirect_time-the time that the redirect was used before the transaction transfer started
Curlinfo_size_upload-Total number of uploaded data
Curlinfo_size_download-The total value of the downloaded data volume
Curlinfo_speed_download-Average Download speed
Curlinfo_speed_upload-Average upload speed
The size of the Curlinfo_header_size-header section
Curlinfo_header_out-Send the requested string
Curlinfo_request_size-size of the requested request in the HTTP request
Curlinfo_ssl_verifyresult-Verify the result of the request by setting the SSL certificate returned by Curlopt_ssl_verifypeer
Curlinfo_content_length_download-Length of downloaded content read from Content-length:field
Curlinfo_content_length_upload-Description of upload content size
Curlinfo_content_type-Content-type: Value of the downloaded content, NULL indicates that the server did not send a valid Content-type:header
return value
If opt is set, its value is returned as a string. Otherwise, returns an associative array that contains the following elements (which correspond to opt), such as setting $opt to Curlinfo_total_time, then the Curl_getinfo () function returns only Total_time, that is, the total transfer time consumed, Setting the $opt parameter is meaningful when you only need to focus on certain transmission information.
"url"
"Content_Type"
"Http_code"
"Header_size"
"Request_size"
"Filetime"
"Ssl_verify_result"
"Redirect_count"
"Total_time"
"Namelookup_time"
"Connect_time"
"Pretransfer_time"
"Size_upload"
"Size_download"
"Speed_download"
"Speed_upload"
"Download_content_length"
"Upload_content_length"
"Starttransfer_time"
"Redirect_time"
Example
<?php//creates a curl handle $ch = Curl_init (' http://www.php.cn/');//Executes curl_exec ($ch);//Checks if there is an error occurred if (!curl_errno ($ch)) { $info = Curl_getinfo ($ch); Echo ' time consuming '. $info [' Total_time ']. ' seconds '. ' ----'.' Get '. $info [' url '];} Close Handlecurl_close ($ch);? >
Code Run Result: