I’m essentially preparing phrases to be put into the database, they may be malformed so I want to store a short hash of them instead (I will be simply comparing if they exist or not, so hash is ideal).
I assume MD5 is fairly slow on 100,000+ requests so I wanted to know what would be the best method to hash the phrases, maybe rolling out my own hash function or using hash('md4', '...'
would be faster in the end?
I know MySQL has MD5(), so that would complement a bit of speed on the query end, but maybe there’s further a faster hashing function in MySQL I don’t know about that would work with PHP..
Advertisement
Answer
CRC32 is pretty fast and there’s a function for it: http://www.php.net/manual/en/function.crc32.php
But you should be aware that CRC32 will have more collisions than MD5 or even SHA-1 hashes, simply because of the reduced length (32 bits compared to 128 bits respectively 160 bits). But if you just want to check whether a stored string is corrupted, you’ll be fine with CRC32.