Executing the PHP/CURL command sets into action all the options defined with the curl_setopt()
function. This command executes the previously configured session (referenced by $s
in Example A-18).
You can execute the same command multiple times or use curl_setopt()
to change configurations between calls of curl_exec()
, as long as the session is defined and hasn’t been closed. Typically, I create a new PHP/CURL session for every page I access.
Once a curl_exec()
command is executed, additional information about the current PHP/CURL session is available. Example A-19 shows how to use the curl_getinfo()
command.
Example A-19. Getting additional information about the current PHP/CURL session
$info_array = curl_getinfo($s);
The curl_getinfo()
command returns an array of information, including connect and transfer times, as shown in Example A-20.
Example A-20. Data made available by the curl_getinfo()
command
array(20) { ["url"]=> string(22) "http://www.schrenk.com" ["content_type"]=> string(29) "text/html; charset=ISO-8859-1" ["http_code"]=> int(200) ["header_size"]=> int(247) ["request_size"]=> int(125) ["filetime"]=> int(-1) ["ssl_verify_result"]=> int(0) ["redirect_count"]=> int(0) ["total_time"]=> float(0.884) ["namelookup_time"]=> float(0) ["connect_time"]=> float(0.079) ["pretransfer_time"]=> float(0.079) ["size_upload"]=> float(0) ["size_download"]=> float(19892) ["speed_download"]=> float(22502.2624434) ["speed_upload"]=> float(0) ["download_content_length"]=> float(0) ["upload_content_length"]=> float(0) ["starttransfer_time"]=> float(0.608) ["redirect_time"]=> float(0) }
The curl_error()
function returns any errors that may have occurred during a PHP/CURL session. The usage for this function is shown in Example A-21.
Example A-22 shows a typical error response.