This is something I have been wondering about. Is it faster to have MySQL handle my md5 hashing or should I let PHP handle it?
Actually I think the MySQL MD5 implementation will be faster.
PHP's native md5() has a bit of a messy implementation of the algorithm. When hashing MD5 with PHP5 I would recommend to use hash('md5',$var); which is proved to be faster.
Make your own benchmarks though.
See this page (Comment at the bottom).
0.33311605453491: hash/md5
1.0671429634094: md5
just comparing the performance, there won't be any noticeable difference (i think the mysql-implementation will be a very very [...] tiny little bit faster).
try to use the solution that results in more redable (and that way easier maintainable) code. for me, this is doing things like hashing in php, but i don't know what your code looks like, so maybe letting mysql do the job is easier for you.
PS: if you're using this for passwords, think about using another algorithm for hashing (sha256 for example). for more information, take a look at wikipedia and read about collisions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With