Jump to content

System availability check - Don't want to do a DB query


watsocd

Recommended Posts

I currently have a function that checks my application for availability. It checks a database record to determine of the application is available.

 

The problem is that it is still using a DB query to check for system availability. If I take the DB off line for maintenance, the system availability function crashes. I know I can catch this but, I may want to tell clients that the application is not available without actually taking the DB off line.

 

So, another way I have thought about programming this would be to have a small text file with a single 1 or 0 character that would indicate the application is available. However, with this method, I am worried that reading that text file thousands of times will effect application performance.

 

Is there another way without doing a DB query to achieve the same result.

 

Suggestions.

 

PHP 5.2.3

 

Chuck

Link to comment
Share on other sites

In short terms no, because the data is in the database and can no not be reached without a query, however a work around could include using a cron job to get each jobs aviablilty every 15 minuets or so, store it in a flat file and then have a little logic saying if  db is down check log file for current condition of application.  This isn't a perfect solution, however it provides a way to accomplish storing db data in case of a disaster.

Link to comment
Share on other sites

My thinking was that I would have an Admin page in my PHP Web front application that would modify the setting in the text file. Writing to the file would be done very infrequently. SO this would take care of creating and updating the text file.

 

The application that wants to check for system availability is a web service using NuSOAP. Each time a web service is called, the first thing the service does is make a check to see if the system is marked as available.

 

Reading the text file to check for system availability could be done be done many thousands of times an hour. The DB method is fast but it is still using the database that that is what I am trying to prevent.

 

Thanks for the quick help.

 

Chuck

Link to comment
Share on other sites

if your using the standard mysql connection with php you can do something like this

 

$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')

    or die('Could not connect: ' . mysql_error());

 

if it cannot connect to the DB it will print on the screen "Could not connect: _SERVER_ERROR_"

Link to comment
Share on other sites

But that solution does not cover when the DB is not actually off line but just in standby for maintenance operations, testing, or i just want to unload the system for some reason and not provide any full web service functionality at that time.

 

Here is a solution I came up with.

 

function ServerAvailable()
{
include('system.php');
return SYSTEM_AVAILABLE;
}

 

The system.php file is as follows. It would be created/modified by a PHP application elsewhere.

 

<?php
define(SYSTEM_AVAILABLE,true);
?>

 

The value would be changed to false to signify that the system is not available.

 

My application code would then be:

if (ServerAvailable()) {
...
My application code.
...
}

 

This would make core PHP do the work and not some file operations in actual PHP source code.

 

Performance opinions?

 

Link to comment
Share on other sites

Although your solution does not make a query to the DB, it still does not resolve my issue is the DB is not physically off line

 

I may want to take unload the DB for some reason. Shut down web services for testing or some other reason while still having the DB running/on line.

 

Chuck

Link to comment
Share on other sites

Then what you are asking is impossible in any sense of anything.

 

It be like saying I want to have this, but I don't want it. Your phrasing doesn't make sense.  If you are that concenerned make a back up database that goes live when the main is down for testing, or better yet just test on the back-up/secondary server.  Mysql databases are easy to make up/clone/copy.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.