Re: Re: Cache

From: Date: Tue, 17 May 2005 00:18:54 +0000
Subject: Re: Re: Cache
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-215345@lists.php.net to get a copy of this message
...
Hmmmm... well, file_get_contents() doesn't lock the file so I'm interested in how you're accomplishing this feat. Perhaps you're creating a temporary directory (atomic IIRC) for the filename and then flocking that? I dunno, I hate race conditions.
I was to fast with that, I didn't look into it enough.. What _would_ be the fastest way (+locking) to do this?
I haven't tested either of these options, but two ideas come to the top of my head: 1. if( mkdir($filename. '.lck') ) $text = file_get_contents($filename); /* be sure to rmdir($filename . '.lck') when operation is complete */ 2. regular steps of fopen(), flock() / mkdir(), fgets(), fclose(), flock() / rmdir() In any case you will find the user notes for flock() are useful: http://php.net/manual/en/function.flock.php
You might also want to consider the security of the data that goes into your cache'd $_APP data. Because any file that is created by PHP is going to be in pretty much the same boat as the default session files and on a shared server, well...
That's from a different thread, and is a different issue. I agree with your argument though, I'm aware of this risk, but most of the time I code on dedicated servers anyway =) grt, Evert
Lucky you! Hey what can I say except that I can occasionally remember more than simply what is on screen *right now* and I try to put it all together when I can.

« previous php.general (#215345) next »