Database Read Only Mode and Login Functions

5 posts by 3 authors in: Forums > CMS Builder
Last Post: January 11, 2017   (RSS)

By Steve99 - January 10, 2017

Hello,

Although these are rare occurrences, there are times we've experienced a primary cloud database server hiccup where it goes into read only mode and kicks over to redundant secondary database server.

For websites utilizing the Website Membership plugin, users are unable to login even if just to view member only content (login functions include writing last login, etc).

Question, is there a method with CMSB to detect if a database is in read only mode and set the result to global var?

I'd be interested in using that for the following front-facing items:
- Bypass Last Login field update so Website Members can still view member only content
- Disable other website features that would rely on writing to the database (Profile Update, Password Reset, Simple Cart Purchases, etc.)

Thank you,
Steve

By ross - January 10, 2017

Hi Steve

Thanks for posting.

I'll check with the rest of the team on this to see what options we have and get back to you.

Let me know any other questions in the meantime.

Thanks!

-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

By Dave - January 11, 2017

Hey Steve, 

Is it just the database, or the whole filesystem?  If it's the filesystem too you could just use the PHP is_writable() function to check a file: 
http://php.net/manual/en/function.is-writable.php

Generally, what you might want to do is just show a temporary page indicating the server is temporarily unavailable.  Because there's likely going to be lots of things that require write access to the db/filesystem.  

Hope that helps!

Dave Edis - Senior Developer

interactivetools.com

By Dave - January 11, 2017

Hi Steve, 

It might be more hassle then it's worth to pursue.  But you could try something like this: 

$isReadOnly = mysql_get_query("SELECT @@GLOBAL.read_only", true)[0];
if ($isReadOnly) {
  header('HTTP/1.1 503 Service Temporarily Unavailable');
  header('Status: 503 Service Temporarily Unavailable');
  header('Retry-After: 7200'); // in seconds
  print "Server is currently unavailable, please try back later!";
  exit;
}

Or just hide the errors Website Membership returns with @.  I think all it updates is the last login date and that's not critical in most cases.

Hope that helps!

Dave Edis - Senior Developer

interactivetools.com