Computing hashes in PHP

I've done a little benchmark of PHP5's hashing functions, and especially the two most widely used hashing algorithms: MD5 and SHA-1. Results are surprising: PHP's default methods (namely, md5() and sha1()), aren't optimal at all... although there are faster equivalents included in one of the modules activated by default since PHP 5.1.2! The hash module offers functions to compute hashes of strings (hash()) or files (hash_file()), and even incremental (streaming) hashes, or HMAC keyed hashes!

My benchmark was done on a quad-Xeon machine, running Debian, with many custom-built packages; so take the results for what they are: the representation of a particular situation. The general conclusions drawn from the test are widely-applicable, though. SHA-256 hashing is included to show that even more complex hashing algorithms are executed faster than simpler ones using the default PHP functions. Please note that there is no "native" function to compute SHA-256 hashes in PHP.

Comparison of hashing functions in PHP

Lire la suite