Jump to content

new with questions about subdate.


makaiser

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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)

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.