Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the highest performance hashing algo available in php when security is NOT at stake?

Tags:

People also ask

What hashing algorithm does PHP use?

PHP has a total of 46 registered hashing algorithms among which “sha1”, “sha256”, “md5”, “haval160, 4” are the most popular ones. $string: This parameter expects the string to be hashed. $getRawOutput: This optional parameter expects a boolean value, on TRUE the function returns the hash in a raw binary format.

Does PHP support sha256?

PHP offers the built-in function hash() . The first argument to the function is the algorithm name (you can pass algorithm names like sha256, sha512, md5, sha1, and many others).


we use md5 as a hashing algorithm in many parts of our code.

security in this context is NOT an issue. we just use md5 as a method of generating a unique identifier to store various items in apc etc.

collisions are an issue. although unlikely, it would cause some major issues.

anyone want to suggest something lighter on the cpu?

thanks.


we have just done some testing with md5 vs crc32.

using the following snippet:

<?
$start=microtime(true);
for($i=1;$i<=1000000;$i++){
    md5(rand(10000000,99999999)); <--- crc32 tested here too.
}
$end=microtime(true);
echo $end-$start."\n";
?>

there results are as follow:

md5:

1.4991459846497
1.7893800735474
1.4672470092773

crc32:

0.97880411148071
0.94331979751587
0.93316197395325

so it would appear crc32 is about 1/3 faster then using md5.