note 56215 added to function.crc32

From: Date: Sat, 27 Aug 2005 12:46:12 +0000
Subject: note 56215 added to function.crc32
Groups: php.notes 
Request: Send a blank email to php-notes+get-94260@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: <? // $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. ---- Manual Page -- http://www.php.net/manual/en/function.crc32.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+56215 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56215&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56215&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56215&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56215&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56215&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56215&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+56215&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#94260) next »