Skip to content

Commit d49186a

Browse files
committed
Merge pull request php-curl-class#251 from zachborboa/master
Allow specifying a buffer when using Curl::verbose()
2 parents fd3a2a8 + 99ef5d5 commit d49186a

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/Curl/Curl.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class Curl
66
{
7-
const VERSION = '4.7.1';
7+
const VERSION = '4.8.0';
88
const DEFAULT_TIMEOUT = 30;
99

1010
public $curl;
@@ -795,9 +795,15 @@ public function unsetHeader($key)
795795
* @access public
796796
* @param $on
797797
*/
798-
public function verbose($on = true)
798+
public function verbose($on = true, $output=STDERR)
799799
{
800+
// Turn off CURLINFO_HEADER_OUT for verbose to work. This has the side
801+
// effect of causing Curl::requestHeaders to be empty.
802+
if ($on) {
803+
$this->setOpt(CURLINFO_HEADER_OUT, false);
804+
}
800805
$this->setOpt(CURLOPT_VERBOSE, $on);
806+
$this->setOpt(CURLOPT_STDERR, $output);
801807
}
802808

803809
/**

tests/PHPCurlClass/PHPCurlClassTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2526,4 +2526,24 @@ public function testMemoryLeak()
25262526
}
25272527
}
25282528
}
2529+
2530+
public function testAlternativeStandardErrorOutput()
2531+
{
2532+
// Skip test on HHVM due to "Segmentation fault".
2533+
if (defined('HHVM_VERSION')) {
2534+
return;
2535+
}
2536+
2537+
$buffer = fopen('php://memory', 'w+');
2538+
2539+
$curl = new Curl();
2540+
$curl->verbose(true, $buffer);
2541+
$curl->post(Test::TEST_URL);
2542+
2543+
rewind($buffer);
2544+
$stderr = stream_get_contents($buffer);
2545+
fclose($buffer);
2546+
2547+
$this->assertNotEmpty($stderr);
2548+
}
25292549
}

0 commit comments

Comments
 (0)