Welcome Guest, Not a member yet? Register   Sign In
Caching on shared NFS
#1

[eluser]skylerrichter[/eluser]
When trying to use output caching on a server that uses a shared file system or NFS I get a error that says "403 Server failed to respond". I tracked it down to the flock() functions in the output cache class.

I had to comment out the following lines to get caching to work:

Code:
//if (flock($fp, LOCK_EX))
//{
    fwrite($fp, $expire.'TS--->'.$output);
    //flock($fp, LOCK_UN);
//}
//else
//{
    //log_message('error', "Unable to secure a file lock for file at: ".$cache_path);
    //return;
//}

and

Code:
//flock($fp, LOCK_SH);
    
$cache = '';
if (filesize($filepath) > 0)
{
    $cache = fread($fp, filesize($filepath));
}
    
//flock($fp, LOCK_UN);

If you check the following documentation http://theserverpages.com/php/manual/en/....flock.php I guess its a common issue theres a few ways to go about fixing it.

upon further inspection I found there are a few other classes using flock(). Including the log class, which stops CI from functioning properly if you are on a shared NFS server.

Thanks
#2

[eluser]er0k[/eluser]
Yes, I just ran into this problem and after a few hours of frustration came to the same conclusion. Wish I had found this thread first :p

I have database caching enabled in one of my apps, which worked fine on our dev server using a local filesystem, but as soon as we moved into production (hosted from an NFS mount), the db caching ground to a halt. I commented out the flock() lines in the file_helper.php and this seems to have solved it.

From the PHP man page on flock():

Quote:PHP supports a portable way of locking complete files in an advisory way (which means all accessing programs have to use the same way of locking or it will not work).

It would be great if CI had a global option to disable file locking for situations like this.
#3

[eluser]skylerrichter[/eluser]
I agree, Being able to disable file locking in the config.php file would probably be the best solution. I found a few ways to emulate file locking on NFS servers but they were all pretty hack-ish so a simple preference in the config.php file would be ideal.

Unfortunately I submitted this in the bug tracker quiet some time ago and have never received a response. Hopefully this issue gets noticed as many of my projects are built on NFS servers and I find my self commenting out the flock() functions in too many CodeIgnter installs.




Theme © iAndrew 2016 - Forum software by © MyBB