View Full Version : Handling file-read failure

01-02-2007, 09:21 PM
I'm kinda new with php, but I'm dying to know how to do the following. But can't seem to get the syntax right. Here's the pseudo code...

Page Refresh = 30 secs
--Read file-a.txt
--file-a.txt not available?
----read file-b.txt
----file-b not available?
------do nothing... (page will refresh in 30 secs and repeat the process)

The problem:
I have a lot of visitors accessing my site and a lot of times the page becomes inaccessible if it refreshes at just the right (wrong) time while it's being read/written to. Instead of the page locking up or giving a server error, I want to be able to try to read a secondary file as a backup.

How can I achieve the logic above?

Thanks for your help!


01-02-2007, 10:10 PM
You can lock files with flock() (http://www.pwp.net/flock).