Re: serialize and cache handling

From: Date: Wed, 09 May 2007 17:47:20 +0000
Subject: Re: serialize and cache handling
References: 1 2 3 4 5 6 7 8 9 10 11  Groups: php.internals 
Request: Send a blank email to internals+get-29383@lists.php.net to get a copy of this message
> If his cache had no locking before, what changed? Well, I have been using several cache classes. A good cache class is the pear cache light. This cache is serializing your data and write this data to a file - of course with file locking. I could imagine, that a improved serialize-function could work like this: $fp = @fopen($filename, "wb"); if ($fp) { @flock($fp, LOCK_EX); serialize($data,$fp); @flock($fp, LOCK_UN); @fclose($fp); } This method makes it possible to decide, if you want to use a locking function or not. The same technique could be applied to imagepng (and others): instead of writing imagepng($img,"/path/to/file"); it would be better to write $fp = @fopen($filename, "wb"); if ($fp) { @flock($fp, LOCK_EX); imagepng($img,$fp); @flock($fp, LOCK_UN); @fclose($fp); } This way, you can decide, if you want to use locking functions or not. I think, this could be a big improvement (until now you have to use imagepng in combination with ob_start / ob_get_contents / ob_end_clean to cache images in a secure way). Mathias

« previous php.internals (#29383) next »