Hi Guys/Gals-

...not sure exactly how to approach this problem....

Basically, a user on our site will be presented with an option and they have a two-hour window to respond--a db record is tagged when the countdown starts. If they do respond, all is well. If they don't, a script should automatically run to perform MySQL db tasks.

As there is no way of knowing if the user will still be around, a session-based solution won't work.

Right now, we're looking at a cron job fired hourly to see if there are any suitably flagged db records whose 2-hour countdown has expired. To me, this seems like a waste of system resources, as the job will run 24 times a day, even when there are no updates to make (it has to check).

Ideally, when the two-hour countdown begins, a session-independent process would start -- almost like a user-defined cron job -- and at the end would check if any changes need to be done; better yet, if the user does respond, the process would be cancelled.

Can anyone point me in the right direction to implement such a thing? Is it even possible?

Many thnx for solutions, possible approaches, or insightful comments...

-Midgard

Member Avatar for diafol

You can run a cron job every 24 hours for cleaning out expired records, but you can check for 2 hour expiry time with your scripts, can't you? Your SQL should be able to search for times within a 2 hour period.

Yup.

The only drawbacks are:

We're trying to keep this as real-time as possible. Running a cron every two hours would make the maximum time between the 2-hour-expiration window to be almost 4 hours (i.e. if the cron ran at 1:00, the user started the countdown at 1:01, it would not have expired by the next cron, so when it did, it would be almost 2 hours (1 hour, 59 minutes) 'late'...so we were thinking about hourly crons to shave that time in half...

...and we'd also have a cron running hourly, whether or not there was anything for it to process...

so, to my original question, I'm wondering if there's any way for the user to initiate a system-level (non-session) event to run the update, or to somehow set a trigger in MySQL to fire a script at a specific time....or something else?

...However, I think I'm stuck with an hourly cron, but I wanted to first consult with y'all to see if there was a better way to proceed....

Thnx,

-Midgard

Member Avatar for diafol

Here's my point. Why do you need to run a cron more than once a day? When you retrieve info from the DB, the record should have a timestamp showing the expiry time. So any decisions with regard to actions to implement can work off that? Or have I missed something?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.