note 15410 added to function.gzencode

From: Date: Sun, 09 Sep 2001 03:48:54 +0000
Subject: note 15410 added to function.gzencode
Groups: php.notes 
Request: Send a blank email to php-notes+get-17840@lists.php.net to get a copy of this message
I was almost discouraged when I didn't find a gzdecode() function! However, fear not, for I'll contribute my work... :) function alt_gzdecode($str) { // seed with microseconds since last "whole" second. mt_srand((float)microtime()*1000000); $eh="/tmp/php-" . md5(mt_rand(0,mt_getrandmax())) . ".gz"; $fd=fopen($eh,"w"); fwrite($fd,$str); fclose($fd); $fd = gzopen ($eh, "r"); $str=gzpassthru($fd); unlink($eh); return $str; } It's only ugly point is that it does not check to see if the file already exists. You may also have to adjust reference names like $str and $fd if they stomp on your code. (Sorry, but this is all you get atm! ;} ) If your conserned about a race condition, cry for a internal gzdecode() function that actualy functions... I spent about 3 hours straight debugging this problem. I know the input data was valid, becuase I validated it with MD5() to compare to the md5's I had made of the input data before hand. I'm not sure whats up with gzuncompress or gzinflate, but this works in its place . . . Enjoy! http://www.php.net/manual/en/function.gzencode.php

« previous php.notes (#17840) next »