> 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

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to