jesushax Posted May 12, 2009 Share Posted May 12, 2009 hi all, im tryign to create error notification if my mysql database goes down i have an errorpage set up to email me if the mysql goes down but i only want to be emailed once not everytime someone vists the site and gets redirected to the error page so someone goes to mysite.com mysql is down so goes to mysite.com/errorpage.php?mysql now i want to run a function that emails me and i only want to be emailed once, anyone know how i could achieve this? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/157823-run-function-only-first-page-visit/ Share on other sites More sharing options...
Ken2k7 Posted May 12, 2009 Share Posted May 12, 2009 But if you only want it to email once, how would you get any future issues? Quote Link to comment https://forums.phpfreaks.com/topic/157823-run-function-only-first-page-visit/#findComment-832410 Share on other sites More sharing options...
PFMaBiSmAd Posted May 12, 2009 Share Posted May 12, 2009 You would need to store a value on your server (in a file) or you could simply just create and delete a file to serve as a flag. You would either set the value or create the file when the first failure email is sent. The code would then check for the value or the existance of the file and not send further emails. You would then need to clear the value or delete the file upon a successful connection to the database server. Quote Link to comment https://forums.phpfreaks.com/topic/157823-run-function-only-first-page-visit/#findComment-832419 Share on other sites More sharing options...
jesushax Posted May 12, 2009 Author Share Posted May 12, 2009 yeah i forgot to mention id need to reset the value after the problem has been rectified can anyone sample me some code that will create a textfile or whatever file and put a 1 in it? then ill either figure out a code to update it to a 0 or ill change the result back to 0 then i caould run an if statement to check for a 1 if results is a 1 email me Thanks also would this file need chmod permissons? and would giving this file permissons, leave a security vunreability? Quote Link to comment https://forums.phpfreaks.com/topic/157823-run-function-only-first-page-visit/#findComment-832432 Share on other sites More sharing options...
MatthewJ Posted May 12, 2009 Share Posted May 12, 2009 $myFile = "testFile.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = "1"; fwrite($fh, $stringData); fclose($fh); Quote Link to comment https://forums.phpfreaks.com/topic/157823-run-function-only-first-page-visit/#findComment-832479 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.