Cache Error

From: Date: Mon, 20 Aug 2001 17:04:46 +0000
Subject: Cache Error
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-1626@lists.php.net to get a copy of this message
There seems to be a cache bug, it took a while to figure out. This is not exactly a bug more of a feature, when saving userdata. When giving a rather large string with new lines as userdata the cache seems to get corrupted >>> from Cache_Container_File::save // file format: // 1st line: expiration date // 2nd line: user data // 3rd+ lines: cache data $expires = $this->getExpiresAbsolute($expires); fwrite($fh, $expires . "\n"); fwrite($fh, $userdata . "\n"); fwrite($fh, $this->encode($cachedata)); >>> the user data gets written to the beginning if the cache file with a new line, at first I thought it was the new line that was causing it but looking into the fetch method >>> from Cache_Container_File::fetch // file format: // 1st line: expiration date // 2nd line: user data // 3rd+ lines: cache data $expire = trim(fgets($fh, 11)); $userdata = trim(fgets($fh, 257)); $cachedata = $this->decode(fread($fh, filesize($file))); fclose($fh); >>> it seems that the fetch method expects the data to be smaller than 256 bytes. So there are two pitfalls a new lines in userdata and userdata larger than 256 bytes. The newlines problem is easily solved but I have no idea how to find out the size of strings in php. Are there differences between char sizes on different OS's and what is the size per char in php strings, I think it's 8b but this is only a blatant assumption. yavo The difference between a good man and a bad one is the choice of cause - William James

« previous php.pear.dev (#1626) next »