What is the absolute fastest way to hash a string in PHP?
I have read that md5 can be relatively slow but am unsure of the alternatives.
Basically, i have a function that i need to squeeze every last bit of performance possible out of and within that function i have a string say “yada yada yada” and i need it hashed in someway so it becomes one string.
I should note that security is no issue here – i simply need a single unique string representation, as its for a cache key.
The whole point of a hash is that it’s -not- fast. The faster the hash is the faster it can be cracked.
By that logic, the less secure the hash is – the faster it’ll be. If you’re going to favour such logic I suggest you either stop what you’re doing or use encryption instead.
In response to your update
It sounds like you may want a
CRC. Again it’s worth mentioning that typically the faster the check is the less combinations exist for the particular algorithm, and thus it’s less likely to be a “unique representation”.The associated PHP documentation can be found here:
hash function with crc32/crc32b