Still Trying to Protect .htaccess

I wrote about my new attempt to protect the .htaccess file from being corrupted by simultaneous writes from WP Better Security in my last post.  My implementation didn’t work and the site went down again with a server configuration error message.

I reimplemented the same flock method I described earlier but this time, instead of directly locking the .htaccess file, I locked a dummy file.  My new method opens the dummy and attempts to lock it.  If the lock is successful, then it goes ahead with the rest of the function that opens and modifies .htaccess.  After that closes, the lock on the dummy file is released and the file is closed.

My thinking is that the entire section of code dealing with the .htaccess file should now only be able to be accessed by one calling thread at a time.  I’m not really sure why my last idea didn’t work but if this method also fails, then clearly flock will not help me.

Edit 7-19-13

The new method did indeed work.  The .htaccess file has not been corrupted since implementing this new fix back on April 17th.

Edit 9-26-13

I wrote a new article to more clearly explain the changes I made.  You can find it here.