makaiser Posted July 25, 2007 Share Posted July 25, 2007 OK, new to this forum, struggling with something here. All I'm after is a simple php/mysql script that checks to make sure something isn't stuck in the queue, and if there is something stuck, to send a mail off. Currently what I've started with. $query = "SELECT orderid FROM store_soap_queue WHERE done != 1 AND started >= SUBDATE(NOW(), INTERVAL 10 MINUTE)"; $results = @mysql_query($query); if($results){ $orderid = array(); while($row = @mysql_fetch_array($results)){ $orderid[] = $row['orderid']; } $notify = print "The order ID that didn't go thru: $orderid at [".date('Y-m-d h:i:sa')."]"; $mailaddress = "name@addresswhatever.com"; $mailsubject = "Stuff still in queue"; $mailbody = $notify; mail($mailaddress,$mailsubject,$mailbody); } I know I'm probably messing something up with the subdate() function. But I could be off, and am not the brightest star in the sky when it comes to mysql/php. Quote Link to comment Share on other sites More sharing options...
Wildbug Posted July 26, 2007 Share Posted July 26, 2007 You could use "NOW() - INTERVAL 10 MINUTE" alone instead of SUBDATE(). Do you mean "less than or equal to" instead of greater than/equal to? Check for errors returning from the mysql_query call instead of hiding them; try "mysql_query(...) or die mysql_error();" for quick debugging. Quote Link to comment Share on other sites More sharing options...
makaiser Posted July 26, 2007 Author Share Posted July 26, 2007 I think I'm making this to difficult, I really don't need to know which items didn't make it through, rather just that something is stuck. $query = "SELECT * FROM store_soap_queue WHERE done != 1 AND started <= NOW(),- INTERVAL 10 MINUTE"; $results = @mysql_query($query); if($results){ $notify = print "An order didn't go through"; $mailaddress = "123@abc.com"; $mailsubject = "Unfinished business in queue!"; $mailbody = $notify; mail($mailaddress,$mailsubject,$mailbody); } else{ print "Nothing stuck in queue \n"; } what do you think? Quote Link to comment Share on other sites More sharing options...
akitchin Posted July 26, 2007 Share Posted July 26, 2007 your original query was fine, your operator was wrong. you need to select those whose date is LESS than or equal to 10 minutes ago - if it's greater than or equal to 10 minutes ago, it means it was started after ten minutes ago. remember that a bigger date means more recent, whereas a smaller date means older: SELECT orderid FROM store_soap_queue WHERE done != 1 AND started <= SUBDATE(NOW(), INTERVAL 10 MINUTE) Quote Link to comment 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.