note 56215 modified in function.crc32 by danbrown

From: Date: Thu, 06 Oct 2011 21:32:00 +0000
Subject: note 56215 modified in function.crc32 by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-183690@lists.php.net to get a copy of this message
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. --was-- 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: <? // $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. http://php.net/manual/en/function.crc32.php

« previous php.notes (#183690) next »