Are there any best practices to follow when implementing PHP scripts for server status checks and automatic redirection?

When implementing PHP scripts for server status checks and automatic redirection, it is important to follow best practices to ensure efficiency and security. One common approach is to use cURL to check the server status and then redirect users based on the response code.

<?php
$url = 'http://www.example.com';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);

if ($http_status == 200) {
    header('Location: http://www.example.com/success.php');
} else {
    header('Location: http://www.example.com/error.php');
}
curl_close($ch);
?>