Hudzilla.org - the homepage of Paul Hudson
Contents > Networks > Curl Wish List | Report Bug | About Me ]

15.10.4     Debugging Curl

This is NOT the latest copy of this book; click here for the latest version.

As it works with so many different network protocols, it is very easy to make mistakes when using Curl. You can speed up your debugging efforts by using CURLOPT_VERBOSE to have Curl output detailed information about its actions.

To give you an idea of how CURLOPT_VERBOSE affects the output of your script, here is a script we used earlier rewritten to add CURLOPT_VERBOSE:

<?php
    $curl
= curl_init();
    
curl_setopt ($curl, CURLOPT_URL, "http://www.php.net");
    
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    
curl_setopt($curl, CURLOPT_VERBOSE, 1);

    
curl_exec ($curl);
    
curl_close ($curl);
?>

Note that CURLOPT_RETURNTRANSFER was used but the output from curl_exec() was ignored - this is because the extra data provided by CURLOPT_VERBOSE is actually sent straight to the browser irrespective of CURLOPT_RETURNTRANSFER, so by ignoring the output of curl_exec() the script will only print out the debugging information. Here is what you should get:

* About to connect() to www.php.net:80
* Connected to php.net (64.246.30.37) port 80
> GET / HTTP/1.1 Host: www.php.net Pragma: no-cache Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*
< HTTP/1.1 200 OK < Date: Fri, 06 Feb 2004 22:13:29 GMT
< Server: Apache/1.3.26 (Unix) mod_gzip/1.3.26.1a PHP/4.3.3-dev
< X-Powered-By: PHP/4.3.3-dev
< Last-Modified: Fri, 06 Feb 2004 22:14:38 GMT
< Content-language: en
< Set-Cookie: COUNTRY=GBR%2C213.152.58.41; expires=Fri, 13-Feb-04 22:13:29 GMT; path=/; domain=.php.net
< Connection: close
< Transfer-Encoding: chunked
< Content-Type: text/html;charset=ISO-8859-1
* Closing connection #0

Note that lines that start with > are headers sent by Curl, lines that start with < are headers sent by the responding server, and lines that start with * are Curl informational messages.





<< 15.10.3 The abridged list of Curl options   15.11 Custom data stream handling >>
Table of Contents
Want to see this stuff in print? PHP in a Nutshell takes the core topics covered here, adds in thousands of edits from the editorial team and myself, and combines them to make an unbeatable reference for PHP programmers at all levels.



My latest book has hundreds more tips on how to use PHP, Apache, and MySQL, plus Perl, Python, shell scripts, performance tuning, and more!



Top-right shadow
 
Bottom-left shadow Bottom shadow

Comments from other readers
Be the first to add a comment to this chapter!



Add comment
Please note that by posting a comment here you are committing it to the public domain. This is important so that others can make use of your code themselves, and also so that I can incorporate helpful notes directly into the main text. Comments are limited to 2000 characters in length.

If you are reporting an error in the content, please tell me directly.

Your name/email address:
Your comment:
 
Now, in order to verify that you're a real person, please answer this simple question: what is nine plus ten?
The answer is:
(please write in
numbers, eg 19)


Top-right shadow
 
Bottom-left shadow Bottom shadow