You can catch all curl requests that zf2 application makes during the execution and log them by using CURLOPT_VERBOSE and writing it into one log file by using CURLOPT_WRITEHEADER or curl_getinfo() and read it to show it on ZF Developer Toolbar like this way..
Prepare curl request having CURLOPT_VERBOSE and CURLOPT_WRITEHEADER options like below..
function curl_request($url, $log_file_path) {
//1. Prepare log file to append request details in to this log file
$logfile_fp = fopen($log_file_path, "a+");
//2. Prepare curl request to having CURLOPT_VERBOSE and CURLOPT_WRITEHEADER parameters in it
$request = new Request();
$request->setUri($url);
$request->setMethod('POST');
$client = new Client();
$adapter = new \Zend\Http\Client\Adapter\Curl();
$client->setAdapter($adapter);
$adapter->setOptions(array(
'curloptions' => array(
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $data,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_VERBOSE => 1,
CURLOPT_WRITEHEADER => $logfile_fp,
// Your curl request options here...
// Your curl request options here...
// Your curl request options here...
// Your curl request options here...
// Your curl request options here...
)
));
//3. Execute curl request
$response = $client->dispatch($request);
//4. Get curl request info
$handle = $client->getAdapter()->getHandle();
$request_info = curl_getinfo($handle);
//5. Write curl request info into log file
@fwrite($logfile_fp, implode(",", $request_info);
@fclose($logfile_fp);
}
Explaination :
- Prepare log file to append request details in to this log file.
- Prepare curl request to having CURLOPT_VERBOSE and CURLOPT_WRITEHEADER parameters in it.
- Execute curl request.
- Get curl request info using curl_getinfo().
- Write curl request info into log file
After this you can read log file using zend file reader or fread() to show it on developer toolbar.
OR
Apart from this there are alternative third party workarounds which will track your server traffic by using netstat or tcpdump or wireshark like following way..
You can use netstat. For example:
$ netstat -nputw
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 192.168.2.48:60614 151.101.65.69:80 ESTABLISHED 2527/chrome
tcp 0 0 192.168.2.48:58317 198.252.206.25:443 ESTABLISHED 2527/chrome
Read the netstat's man page for more details.
OR
You can use tcpdump tool on the server outside of your apache to track all network traffic, For example:
$ tcpdump -vv -s0 tcp port 80 -w /tmp/apache_outgoing.pcap
Read the tcpdump's man page for more details.