note 70307 deleted from function.md5 by danbrown

From: Date: Mon, 18 Jul 2011 13:58:35 +0000
Subject: note 70307 deleted from function.md5 by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-181644@lists.php.net to get a copy of this message
Note Submitter: squeegee ---- Regarding the md5_base64 function posted below, since the encoded string will never be longer than 64 characters (the maximum length of a base64 encoded line), and the fact that base64 strings only insert the '=' pad character at the end of an encoded line, instead of using preg_replace, you can just use rtrim. $myhash=rtrim(base64_encode(pack("H*",md5($data))),"="); This will result in a string of 22 characters, suitable for inserting in mysql or whatever. Also, if you are testing against the string in a query in mysql, make sure to use the keyword BINARY, as case matters. The reason for the function in the first place (for me): If you're currently using an md5 hash for a unique index, this will save at least 20 bytes for every record on disk (index + data) and 10 bytes in memory. If you have millions of rows, that can really add up (100 million rows would require about 1 less gigabyte of memory for your key_buffer_size variable in mysql).

« previous php.notes (#181644) next »