Debugging

Previously mentioned in the last section on handling headers, the cu rl_getinfo function also enables you to view requests being sent by cURL. This can be quite useful when debugging. Below is an example of this feature in action.

<?php
$ch = curl_init();
curl_setopt_array(array(
CURLOPT_RETURNTRANSFER => true, CURLINFO_HEADER_OUT => true
));
curl_exec($ch);
$request = curl_getinfo($ch, CURLINFO_HEADER_OUT); ?>
  • CURLOPT_RETURNTRANSFER is set to true in the curl_setopt_array call even though the return value of cu rl_exec isn’t captured. This is simply to prevent unwanted output.
  • CURLINFO_HEADER_OUT is set to true in the curl_setopt_array call to indicate that the request should be retained because it will be extracted after the request is made.
  • CURLINFO_HEADER_OUT is specified in the curl_getinfo call to limit its return value to a string containing the request that was made.

© cURL Extension — Web Scraping

>>> Back to TABLE OF CONTENTS <<<
Category: Article | Added by: Marsipan (30.08.2014)
Views: 359 | Rating: 0.0/0
Total comments: 0
avatar