How can Wireshark be used to analyze and capture network traffic when troubleshooting issues with PHP scripts interacting with external websites?

When troubleshooting issues with PHP scripts interacting with external websites, Wireshark can be used to capture and analyze network traffic to identify any potential communication problems. By inspecting the packets exchanged between the PHP script and the external website, you can pinpoint where the issue lies, whether it's with the request being sent or the response received.

// Example PHP code snippet using cURL to send a request to an external website and capture network traffic with Wireshark
$url = 'https://www.example.com/api';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);

// Add Wireshark capture here to analyze network traffic