What are the best practices for handling and interpreting command line responses in PHP when checking website status?

When checking website status using command line responses in PHP, it is important to properly handle and interpret the output to ensure accurate results. One best practice is to use functions like `exec()` or `shell_exec()` to run the command and capture the response. Then, you can parse the response to extract relevant information such as HTTP status codes or error messages.

// Example code snippet for checking website status using command line response in PHP

// Define the website URL to check
$websiteUrl = "https://www.example.com";

// Run the command to check the website status
$response = shell_exec("curl -I $websiteUrl");

// Parse the response to extract the HTTP status code
preg_match('/HTTP\/1\.\d+\s(\d+)/', $response, $matches);
$httpStatusCode = isset($matches[1]) ? $matches[1] : "Unknown";

// Output the HTTP status code
echo "Website status for $websiteUrl: HTTP $httpStatusCode";