You can catch all the curl requests that zf2 creates at runtime and log them using CURLOPT_VERBOSE and write them to a single log file using CURLOPT_WRITEHEADER or curl_getinfo () and read it to show it on the ZF Developer toolbar this way ..
Prepare a curl request with the parameters CURLOPT_VERBOSE and CURLOPT_WRITEHEADER, as shown 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); }
Explanation:
- Prepare the log file to add the request data to this log file.
- Prepare the curl request for the parameters CURLOPT_VERBOSE and CURLOPT_WRITEHEADER.
- Fulfillment of a request for curling.
- Get turbulence information using curl_getinfo ().
- Recording curl request information in a log file
After that, you can read the log file using the zend file or fread () to show it on the developer's toolbar.
OR
In addition, there are alternative third-party solutions that will track your server traffic using netstat or tcpdump or wirehark, as follows.
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 tcpdump page for more details.
himeshc_IB
source share