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

Example A-18. Executing a PHP/CURL command for session $s

$downloaded_page = curl_exec($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.

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.

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

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.