|
Posted by ljb on 03/03/07 01:38
karl@NOSPAMkarlcore.com wrote:
> I've got a script which writes my blog's RSS feed (rather than dynamically
> generating it each time it is requested), and I'm not sure whether I should
> lock the file while I'm writing it. Truth is, the only way this script
> runs is through cron anyway, and I recently read that "Other processes can
> modify or delete a PHP-locked file if permissions allow." which seems to be
> a waste of time, anyway.
>
> Can someone shed light on this?
PHP's flock() (which actually uses the system call fcntl()) is advisory,
not mandatory. This means it only controls access from tasks that use it.
Cooperating tasks 'agree' to use flock() to control access to the file. A
non-cooperating task which does not use locking can always read/write the
file (if permissions allow).
In your case, what if a request to read the RSS feed file comes in at the
same time your cron job is writing it? So yes, you may need locking.
Navigation:
[Reply to this message]
|