sb1920alk Posted February 6, 2008 Share Posted February 6, 2008 I have a page that updates itself every few minutes (it's an Excel file on a macro loop that saves a copy of itself onto a website as html). It works great, but once in a while Excel will hang and the html file will stop being updated as a result. I have a php page which calls this html file and adds the server time. My question is, can I set something up that will monitor the html page, and if a set amount of time (say, 10 minutes) goes by and the html page has not updated, that it will send me an email? Any help is appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/89655-new-guy-question/ Share on other sites More sharing options...
clearstatcache Posted February 6, 2008 Share Posted February 6, 2008 dunno if i get u right..... $file = "file.html"; $stat = stat($file); if ( (time() - $stat['mtime']) > 600) { // 600 seconds // send email .... } Quote Link to comment https://forums.phpfreaks.com/topic/89655-new-guy-question/#findComment-459353 Share on other sites More sharing options...
Stooney Posted February 6, 2008 Share Posted February 6, 2008 clearstatcache's solution will work as long as you either put it on a cron job, or use ajax to auto run the script every x minutes. Quote Link to comment https://forums.phpfreaks.com/topic/89655-new-guy-question/#findComment-459505 Share on other sites More sharing options...
mmarif4u Posted February 6, 2008 Share Posted February 6, 2008 Cron job is better choice here. About ajax,will runs when page is loaded in browser. Quote Link to comment https://forums.phpfreaks.com/topic/89655-new-guy-question/#findComment-459508 Share on other sites More sharing options...
Stooney Posted February 6, 2008 Share Posted February 6, 2008 I only suggested AJAX because you could use setTimeout() to just loop the ajax function at a set interval, it would work. Quote Link to comment https://forums.phpfreaks.com/topic/89655-new-guy-question/#findComment-459511 Share on other sites More sharing options...
sb1920alk Posted March 13, 2008 Author Share Posted March 13, 2008 Ok, so with the cron job, it will send an email every five minutes, right? For AJAX, it would send an email every time someone accesses the page? There's one other issue with my page. Maybe you can help me with that too. Excel is exporting a chart as a GIF which is part of the page. Once in a while, the GIF does not load, just an empty box in it's place. Refreshing the page manually, or waiting for the auto-refresh usually loads the GIF properly. I'm not sure why this is happening. I think it only happens when the page is trying to load at the exact same time that Excel is saving a new version of the GIF. Any ideas on how to make this not show a blank page? I tried this already: I made an alternate pic with the same dimensions that says, "The chart is being updated, this page will refresh automatically." Using this code: <?php unlink($filename); $filename = 'Chart.gif'; if (file_exists($filename)) { echo '<p align="center"><img border="0" src="Chart.gif" width="932" height="547"></p>'; } else { echo '<p align="center"><img border="0" src="NoChart.JPG" width="932" height="547"></p>'; } ?> ...but it made no difference. The blank box still shows up once in a while, and I've never seen the alternate pic show up. I'm still new to PHP, so I'm not sure which function will work for this. I thought it would be file_exists, but I gues not. Quote Link to comment https://forums.phpfreaks.com/topic/89655-new-guy-question/#findComment-491414 Share on other sites More sharing options...
sb1920alk Posted March 18, 2008 Author Share Posted March 18, 2008 bump Quote Link to comment https://forums.phpfreaks.com/topic/89655-new-guy-question/#findComment-495168 Share on other sites More sharing options...
sb1920alk Posted March 26, 2008 Author Share Posted March 26, 2008 I have more information about the picture issue. It is not, as I originally thought, that the file is being saved by excel and that it's only blanking for a moment. Instead, there is some sort of corruption in the file and it's blanking until the corrupted file is replaced. The excel file is on a 15 second loop. The next time it loops, it saves over the corrupt file, allowing the page displays correctly. I found this out today when I noticed the page showing a blank box where the picture should have been. I quickly stopped the loop on the excel file before it could save another picture. I was not able to access the picture through a browser even by entering it's direct location in the address bar. I was able to access the file directly on the server's hard drive. It opened up as if nothing was wrong when I accessed it directly on the server, but it still wouldn't load from the browser. So I still need a better code than what I've got here because this one is also going down the "true" path: <?php unlink($filename); $filename = 'Chart.gif'; if (file_exists($filename)) { echo '<p align="center"><img border="0" src="Chart.gif" width="932" height="547"></p>'; } else { echo '<p align="center"><img border="0" src="NoChart.JPG" width="932" height="547"></p>'; } ?> I tried a few other functions besides file_exists() but everything I tried either came back as always false or always true. I need one that returns "true" when the file can be display and "false" when it cannot. As for the email script: $file = "file.html"; $stat = stat($file); if ( (time() - $stat['mtime']) > 600) { // 600 seconds // send email .... } I have put it on a cron and the email works, but it's emailing me every time the cron runs, so something is wrong with the if() test that is making it say always true. Here's what I'm using now: <?php unlink($stat); $file = "excel.htm"; $stat = stat($file); if ( (time() - $stat['mtime']) > 600) { // 600 seconds mail( "***my email address is here****", "Excel is stuck", "Please exit MS Excel on the web server, then restart it again", "From: ***my email address is here****" ); } ?> The final issue I need help with is also related to the cron script. I only want it to email me once. If I have the cron running every 5 minutes and the excel file freezes up right after I leave work, I'll have way too many emails by the time I get back in the next morning. Can I the cron script read a text file that either says "running" or "sent" before emailing? If is says "running" the script continues as normal. If the script determines that excel.htm is old, then it overwrites the text file with "sent" after it has emailed me. The next time around it will read the text file and see that it says "sent" and skip the email part. If the cron finds that the file is young again it replaces the text file again with "running" Anyways, that's my idea. I'm not sure how to implement it. Better ideas are also welcome. I appreciate your help. Quote Link to comment https://forums.phpfreaks.com/topic/89655-new-guy-question/#findComment-500879 Share on other sites More sharing options...
schme16 Posted March 26, 2008 Share Posted March 26, 2008 I can help with the emails bit. make your email code reflect this: <?php unlink($stat); $file = "excel.htm"; $stat = stat($file); $efmt = @file_get_contents('filemodtime'); if ( (time() - $stat['mtime']) > 600 and time() - $efmt < 700) { // 600 seconds / 10mins mail( "***my email address is here****", "Excel is stuck", "Please exit MS Excel on the web server, then restart it again", "From: ***my email address is here****" ); @file_put_contents('filemodtime', $stat['mtime']); } ?> That should work, it might be clumsy however, so anyone... feel free to elaborate and improve on this. Quote Link to comment https://forums.phpfreaks.com/topic/89655-new-guy-question/#findComment-500928 Share on other sites More sharing options...
sb1920alk Posted March 26, 2008 Author Share Posted March 26, 2008 So how does that work? It only emails if the age of the file is between 600 and 700 seconds? Quote Link to comment https://forums.phpfreaks.com/topic/89655-new-guy-question/#findComment-501695 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.