What method can be used to compare the size of files on different servers in PHP without downloading the second file?

To compare the size of files on different servers in PHP without downloading the second file, you can use the PHP cURL extension to send a HEAD request to the server hosting the second file. This will retrieve the headers of the file, including the content length, without actually downloading the file itself.

$url = 'http://example.com/file.txt'; // URL of the second file
$ch = curl_init($url);

curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);

if ($response !== false) {
    $fileSize = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
    echo "Size of file on server: " . $fileSize . " bytes";
} else {
    echo "Error retrieving file size";
}

curl_close($ch);