What are the best practices for securely comparing hashes between two servers in a PHP application?

When comparing hashes between two servers in a PHP application, it is important to ensure that the comparison is done securely to prevent potential security vulnerabilities such as timing attacks. One common best practice is to use a timing attack resistant comparison function like hash_equals() instead of the regular comparison operator (==). This function compares two strings in a constant time, regardless of their length or content, making it more secure for comparing hashes.

$hash1 = 'hash_from_server1';
$hash2 = 'hash_from_server2';

if (hash_equals($hash1, $hash2)) {
    echo 'Hashes match!';
} else {
    echo 'Hashes do not match!';
}