Executing the PHP/CURL Command

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 Listing A-18).

$downloaded_page = curl_exec($s);

Listing A-18: Executing a PHP/CURL command for session $s

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.

Retrieving PHP/CURL Session Information

Additional information about the current PHP/CURL session is available once a curl_exec() command is executed. Listing A-19 shows how to use this command.

$info_array = curl_getinfo($s);

Listing A-19: Getting additional information about the current PHP/CURL session

The curl_getinfo() command returns an array of information, including connect and transfer times, as shown in Listing A-20.

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)
   }

Listing A-20: Data made available by the curl_getinfo() command

Viewing PHP/CURL Errors

The curl_error() function returns any errors that may have occurred during a PHP/CURL session. The usage for this function is shown in Listing A-21.

$errors = curl_error($s);

Listing A-21: Accessing PHP/CURL session errors

A typical error response is shown in Listing A-22.

Couldn't resolve host 'www.webbotworld.com'

Listing A-22: Typical PHP/CURL session error

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.7.208