Welcome Guest, Not a member yet? Register   Sign In
Cache Functions Suggestions
#18

[eluser]Rick Jolly[/eluser]
Hi Paul. Thank you for responding. I think there are two routes to take:

1) prevent cache file corruption with flock
2) detect cache file corruption from writes during reading

Prevent corruption with flock
I'm no expert, but I haven't come across a reliable way to solve the flock issues. Adding the non-blocking lock (LOCK_NB) seems to be the ideal solution - if it were supported by all operating systems...
[quote author="Paul Burdick" date="1203108520"]...Looking at your fix, you are using LOCK_NB, which is only available on Windows...[/quote]
PHP.net claims that it isn't supported by windows.

Still, as long as the non-blocking lock has some support, it seems worth including. Maybe first detect the OS and add the non-blocking lock if supported.

The locks work on the OS level, and every hack I've seen to replace flock doesn't work. Using rename/copy to replace the cache file would corrupt the file for those users simultaneously reading the file - I've tested that to be sure.

Detect corruption from writes during reading
So if flock is out, and you can't prevent cache file corruption for readers, then the next best thing is to detect corruption. In the event the cache has been updated during a read, then simply don't use the cache. To detect corruption, a hash, checksum, or a simple length of the original data is included in the cache file when writing. When the cache file is read, that check (hash, checksum, or length) is extracted from the file and compared with the same check on the actual data. Of course, the drawback is that there is overhead involved.


Messages In This Thread
Cache Functions Suggestions - by El Forum - 02-01-2008, 04:35 PM
Cache Functions Suggestions - by El Forum - 02-08-2008, 03:11 AM
Cache Functions Suggestions - by El Forum - 02-08-2008, 07:45 AM
Cache Functions Suggestions - by El Forum - 02-11-2008, 03:26 PM
Cache Functions Suggestions - by El Forum - 02-11-2008, 04:24 PM
Cache Functions Suggestions - by El Forum - 02-12-2008, 09:56 AM
Cache Functions Suggestions - by El Forum - 02-12-2008, 10:49 AM
Cache Functions Suggestions - by El Forum - 02-12-2008, 11:00 AM
Cache Functions Suggestions - by El Forum - 02-12-2008, 09:51 PM
Cache Functions Suggestions - by El Forum - 02-13-2008, 03:54 PM
Cache Functions Suggestions - by El Forum - 02-13-2008, 04:35 PM
Cache Functions Suggestions - by El Forum - 02-13-2008, 06:51 PM
Cache Functions Suggestions - by El Forum - 02-14-2008, 04:00 AM
Cache Functions Suggestions - by El Forum - 02-14-2008, 11:58 AM
Cache Functions Suggestions - by El Forum - 02-15-2008, 08:48 AM
Cache Functions Suggestions - by El Forum - 02-15-2008, 08:55 AM
Cache Functions Suggestions - by El Forum - 02-15-2008, 09:02 AM
Cache Functions Suggestions - by El Forum - 02-15-2008, 05:50 PM
Cache Functions Suggestions - by El Forum - 02-15-2008, 06:19 PM
Cache Functions Suggestions - by El Forum - 02-15-2008, 06:34 PM
Cache Functions Suggestions - by El Forum - 03-08-2008, 10:23 AM
Cache Functions Suggestions - by El Forum - 03-13-2008, 08:20 PM
Cache Functions Suggestions - by El Forum - 03-13-2008, 08:25 PM
Cache Functions Suggestions - by El Forum - 03-25-2008, 06:12 AM
Cache Functions Suggestions - by El Forum - 03-25-2008, 06:58 AM
Cache Functions Suggestions - by El Forum - 03-25-2008, 07:27 AM
Cache Functions Suggestions - by El Forum - 03-25-2008, 10:51 AM
Cache Functions Suggestions - by El Forum - 03-25-2008, 11:31 AM
Cache Functions Suggestions - by El Forum - 03-25-2008, 11:37 AM
Cache Functions Suggestions - by El Forum - 04-24-2008, 06:33 AM
Cache Functions Suggestions - by El Forum - 04-25-2008, 11:25 AM
Cache Functions Suggestions - by El Forum - 04-25-2008, 02:03 PM
Cache Functions Suggestions - by El Forum - 04-25-2008, 04:50 PM
Cache Functions Suggestions - by El Forum - 04-29-2008, 05:36 AM
Cache Functions Suggestions - by El Forum - 04-29-2008, 06:15 AM
Cache Functions Suggestions - by El Forum - 04-29-2008, 09:39 AM
Cache Functions Suggestions - by El Forum - 04-29-2008, 10:10 AM
Cache Functions Suggestions - by El Forum - 04-29-2008, 10:23 AM



Theme © iAndrew 2016 - Forum software by © MyBB