PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
// UPDATE THE HTML FILE
// open the file
$handle = fopen("../../cron_results/birthdays.html", "w");
// lock it
flock($handle, LOCK_EX);
// write the contents
fwrite($handle, $str);
// release the lock
flock($handle, LOCK_UN);
// close the file
fclose($handle);
echo 'Birthday list successfully updated.';
This will be ran on a 10 minute cron on a pretty heavily accessed page. It's output goes to an html file that will be included on the index page. During the file writing process will the users experience any errors? I realize that this will only take like a couple hundredths of a second to do (if that), but will the users experience any problems?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
AFAIK, locking the file from within php will not prevent Linux's ability to read the file. So the only time there might be a race condition is when the file is actually being written. It may depend on your filesystem, but I would imagine all the Linux filesystems would have no trouble at all.
I do know by experience that using IIS 4.0 on Windows NT with ASP can cause files to be corrupted and 404 errors to pop up if a user is accessing a page while it is saving to the disk.
I suppose your situation would be similar to if you updated the file via FTP.
Well this is a small portion of the page. At the bottom. and i'm using require(), so I guess the worst that would happen is that the page would terminate at that point. In which case I should use include() instead.
Has anyone had experience with this/read docs about this situation?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
So the file writing process was occuring almost simultaneously. I then refreshed the page that this file was included on a bunch of times and didn't experience any problems.
Does that mean it's OK?
Is there a better way to test it, other than refreshing the page a bunch of times while the loop is running?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Can anybody help me with this?
I'm making a forum by writing and reading into/ from a text file.. everything works well untill somebody hits enter. "feof" takes enter as a new line and everything gets messed up. How can I deal with "enter" and "feof"?
Ah, well see, the file writing will write a very small string (less than 1kb) to an html file once every 30 seconds. This will be the only script ever writing to this file, and it will only be ran once per 30 seconds, and executed by the server.
So it should never be locked by another script at the same time.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
because the file that im writing to is included on a pretty regularly trafficked page.
i don't want the page to read the file at the same time i'm writing it.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.