PHP 8.5.0 Alpha 4 available for testing

Voting

: eight minus five?
(Example: nine)

The Note You're Voting On

Bulk at bulksplace dot com
19 years ago
A faster way I've found to return CRC values of larger files, is instead of using the file()/implode() method used below, is to us file_get_contents() (PHP 4 >= 4.3.0) which uses memory mapping techniques if supported by your OS to enhance performance. Here's my example function:

<?php
// $file is the path to the file you want to check.
function file_crc($file)
{
$file_string = file_get_contents($file);

$crc = crc32($file_string);

return
sprintf("%u", $crc);
}

$file_to_crc = /home/path/to/file.jpg;

echo
file_crc($file_to_crc); // Outputs CRC value for given file.
?>

I've found in testing this method is MUCH faster for larger binary files.

<< Back to user notes page

To Top