Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CURLOPT_VERBOSE not working

Windows 7 x64
PHP 7.2.2 x64

I am trying to view a simple request payload so I have created a PHP file per https://docstore.mik.ua/orelly/webprog/pcook/ch11_07.htm

<?php
$c = curl_init('https://www.google.com');
curl_setopt($c, CURLOPT_VERBOSE, 1);
curl_setopt($c, CURLOPT_POST, 1);
curl_setopt($c, CURLOPT_POSTFIELDS, 'monkey=uncle&rhino=aunt');
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
$page = curl_exec($c);
curl_close($c);

but I get absolutely no output unlike the example which shows that I can expect something like:

* Connected to www.example.com (10.1.1.1)
> POST /submit.php HTTP/1.1
Host: www.example.com
Pragma: no-cache
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*
Content-Length: 23
Content-Type: application/x-www-form-urlencoded

monkey=uncle&rhino=aunt* Connection #0 left intact
* Closing connection #0

$page contains a Google 404 page so I know the request is succeeding.

Does anyone know if there are other settings which I need to address or if I am doing something blatantly wrong? In particular, I am interested in the body of the payload.

Yes, I am aware that curl'ing Google isn't particularly useful; I am trying to get this simple example to work so that I can debug an API interaction which is mysteriously failing.

Updates, per comment request

I cannot do curl -v but print_r( curl_version() ); produces:

Array
(
    [version_number] => 473344
    [age] => 4
    [features] => 2428829
    [ssl_version_number] => 0
    [version] => 7.57.0
    [host] => x86_64-pc-win32
    [ssl_version] => OpenSSL/1.1.0g
    [libz_version] => 1.2.11
    [protocols] => Array
        (
            [0] => dict
            [1] => file
            [2] => ftp
            [3] => ftps
            [4] => gopher
            [5] => http
            [6] => https
            [7] => imap
            [8] => imaps
            [9] => ldap
            [10] => pop3
            [11] => pop3s
            [12] => rtsp
            [13] => scp
            [14] => sftp
            [15] => smb
            [16] => smbs
            [17] => smtp
            [18] => smtps
            [19] => telnet
            [20] => tftp
        )

)
like image 441
MonkeyZeus Avatar asked Apr 04 '18 19:04

MonkeyZeus


1 Answers

tl;dr

CURLOPT_STDERR must be set to something specific.

Setting curl_setopt($c, CURLOPT_STDERR, fopen('/curl.txt', 'w+')); fixed my issue.


As it turns out curl_setopt($c, CURLOPT_VERBOSE, 1); is not printing the output to STDERR for some reason which I have not uncovered. I did not find the output in any of my PHP, Apache, nor Event Viewer logs.

After setting curl_setopt($c, CURLOPT_STDERR, fopen('/curl.txt', 'w+'));, I was able to see the output in the curl.txt file.

I am not sure if this is specific to Windows environments.

like image 76
MonkeyZeus Avatar answered Sep 19 '22 19:09

MonkeyZeus