watsocd Posted September 19, 2007 Share Posted September 19, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/69907-system-availability-check-dont-want-to-do-a-db-query/ Share on other sites More sharing options...
cooldude832 Posted September 19, 2007 Share Posted September 19, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/69907-system-availability-check-dont-want-to-do-a-db-query/#findComment-351109 Share on other sites More sharing options...
watsocd Posted September 19, 2007 Author Share Posted September 19, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/69907-system-availability-check-dont-want-to-do-a-db-query/#findComment-351117 Share on other sites More sharing options...
remlabm Posted September 19, 2007 Share Posted September 19, 2007 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_" Quote Link to comment https://forums.phpfreaks.com/topic/69907-system-availability-check-dont-want-to-do-a-db-query/#findComment-351134 Share on other sites More sharing options...
watsocd Posted September 19, 2007 Author Share Posted September 19, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/69907-system-availability-check-dont-want-to-do-a-db-query/#findComment-351146 Share on other sites More sharing options...
remlabm Posted September 19, 2007 Share Posted September 19, 2007 are you looking to redirect if the MYSQL fails? or still compete the page your loading? if you wanna redirect you can do something like : $link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password') or header("Location: /downpage.html");die; Quote Link to comment https://forums.phpfreaks.com/topic/69907-system-availability-check-dont-want-to-do-a-db-query/#findComment-351151 Share on other sites More sharing options...
watsocd Posted September 19, 2007 Author Share Posted September 19, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/69907-system-availability-check-dont-want-to-do-a-db-query/#findComment-351349 Share on other sites More sharing options...
cooldude832 Posted September 19, 2007 Share Posted September 19, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/69907-system-availability-check-dont-want-to-do-a-db-query/#findComment-351359 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.