1 # http\Client http\Client::setDebug(callable $callback)
3 Set client debugging callback.
6 > This method has been added in v2.6.0, resp. v3.1.0.
10 * callable $callback as function(http\Client $c, http\Client\Request $r, int $type, string $data)
11 The debug callback. For $type see http\Client::DEBUG_* constants.
19 * http\Exception\InvalidArgumentException
25 (new http\Client)->setDebug(function($c, $r, $type, $data) {
26 if ($type === http\Client::DEBUG_INFO) {
27 printf("INFO: %s\n", $data);
30 if ($type & http\Client::DEBUG_OUT) {
32 } elseif ($type & http\Client::DEBUG_IN) {
35 if ($type & http\Client::DEBUG_SSL) {
36 printf("%s <%d bytes of SSL data>\n", $sep, strlen($data));
38 printf("%s %s\n", $sep, str_replace("\n", "\n$sep ", rtrim($data, "\n")));
41 })->enqueue(new http\Client\Request("GET", "http://example.com"))->send();
46 > Except for http\Client::DEBUG_INFO, which always occurs separately, the debug
47 > callback's $type argument contains a bitmask of (http\Client::DEBUG_IN or http\Client::DEBUG_OUT)
48 > and (http\Client::DEBUG_HEADER or http\Client::DEBUG_BODY or http\Client::DEBUG_SSL).
52 INFO: Trying 93.184.216.34...
54 INFO: Connected to example.com (93.184.216.34) port 80 (#0)
58 > User-Agent: PECL_HTTP/2.6.0dev PHP/5.6.19RC1 libcurl/7.50.0-DEV
62 < Cache-Control: max-age=604800
63 < Content-Type: text/html
64 < Date: Thu, 18 Aug 2016 17:55:10 GMT
65 < Etag: "359670651+gzip+ident"
66 < Expires: Thu, 25 Aug 2016 17:55:10 GMT
67 < Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT
68 < Server: ECS (iad/182A)
69 < Vary: Accept-Encoding
71 < x-ec-custom-error: 1
72 < Content-Length: 1270
77 < <title>Example Domain</title>
79 < <meta charset="utf-8" />
80 < <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
81 < <meta name="viewport" content="width=device-width, initial-scale=1" />
82 < <style type="text/css">
84 < background-color: #f0f0f2;
87 < font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
94 < background-color: #fff;
99 < text-decoration: none;
101 < @media (max-width: 700px) {
103 < background-color: #fff;
117 < <h1>Example Domain</h1>
118 < <p>This domain is established to be used for illustrative examples in documents. You may use this
119 < domain in examples without prior coordination or asking for permission.</p>
120 < <p><a href="http://www.iana.org/domains/example">More information...</a></p>
124 INFO: Connection #0 to host example.com left intact