Schedule alarm notification system php - php

I need some help regarding the implementation of the following alarm.. Here's the flow of the program, user login to the system and then they can click the hyperlink create schedule and then from there they can create schedules using the form. After which, user can choose to start this schedules that they created and they can allocate a timeframe to it. For eg, if the user assign the schedule to run at 2pm the system will have a pop up to notify and inform the user to run this schedule probably 15 mins before 2pm..
I would like to know what are the ways to implement this in php and if possible is there any reference i can use on the website? I've tried to find but apparently most scripts are paid etc.

I think you are looking for scheduler kind of thing, to do this in php
you can use scheduler for windows os
cron job for *nix based os

Yes the answer to this question is pretty much related to CRON job. Take a look at this answer
Execute Query on a Specific Date and Time
You need to write a PHP script that scans the db and sees for the user who should be notified (i.e their deadline has arrived). Run this script in the scheduler (maybe every 1 hour) and it will do the magic for you. Good luck with your notifications :)

No cron job is needed if you only notify user with popup on the web site, however, you will need a cronjob if you want to send emails.
You will have to store users schedules (possibly in a db table)
When the user logs in php should check if there's a task due in the schedules table for that user: if yes show the pop up.
You will need to create an ajax call (with users id) that will call a certain php (say ajax.php) file every minute. You can help yourself with jquery.
The ajax.php should check if there was a task due in the past. If yes it returns job details (as json or html, you chose) else it just returns that there are no jobs.
When the calling ajax code recieves an answer from ajax.php, it does nothing if the answer is that there are no jobs or displays a popup with job details recieved from ajax.php.
The user can dismiss the call (delete it from the schedules db table) snooze or reschedule it (update the due date in the schedules db table).
Don't forget about security especially in the ajax.php: it has to check if the user is logged in.
Only if you want to prompt non logged in users by email you will need to set up a cron jobs, that will ping the ajax.php file periodically.

Related

In PHP, how to keep a process running to monitor for an event?

I have a DBMS assignment to create an entire online bidding website that allows users to do many things like bidding on a timed auction, buy-it-now based on timed availability, and search among MANY more things. I've completed the website, with one minor exception: once a user wins a timed auction, that user must be notified that s/he is the winner and given 24hrs to checkout the item.
My early approaches consisted of simple PHP scripts that queried the DB when the user was on the page to see if the bid time ended and to see who the winner is, but there are two things wrong with that approach. 1. The user has to constantly refresh to find out if s/he won -- if they're on the page shopping. 2. If the user doesn't log into the site for a month after the auction ended, s/he will not know for a month that s/he won the auction and therefore misses the 24 hr window to checkout.
I've been reading about cron jobs, but my concern is that, since they are scheduled jobs, there are no convenient times to schedule the jobs so that they get processed efficiently. What I mean is that I can't continuously monitor and let every user who wins know instantly after the auction ends.
I also read on PHP exec( ), but I'm not sure that it's the tool that I need to run this task because once exec( ) finishes, it doesn't re-run.
So I guess, my question is if anyone has an idea of what I could implement to help me with this task.
You should use cron - have it run every minute or so to check the DB to see if some auction ended. The greater problem I think you're construing is the notification to the user. If its the case they may not be on the site (or on some random page when they win) then don't rely on notifying them via the website and certainly not from a PHP request they may or may not make to the site. Instead, consider having the PHP called by cron to check for winners send an email to them to notify them.
Think about Facebook (only because given the user base its the most universally experience example) - they provide a notification area if you're on the site, but if you're not on for a while, they send you an email letting you know something has happened. This is what you should do.
You should reconsider using cron scheduling, you can run jobs at very fast intervals.

PHP front end user queue

I'm building a site where the users can control a webcam to turn it left and right.
Every user gets one minute of action. There is going to be a queuing system on the site that will allow one by one the users to control the camera.
So my question is the following, does anyone have a suggestion on how to build this queuing system? Are there any tutorials or code I can use?
Thanks a lot!
Have a database table to track the queue for example:
queue (id, session_id, start_time, last_update)
When users hit your page, insert them into the queue table. Use a regular ajax call (perhaps 30 seconds) on the page to poll the server to see if the current users turn is up.
If the user is the first record in the table then it's his turn, so update the start_time to the current time and send your ajax response telling the browser to display the UI with the buttons for the camera movement.
When a button is pressed, verify on the server side that it is infact this users turn and his start_time was < 1min ago, before allowing the action. If his turn is over, delete him from the table so that the next user becomes the first record and gets his turn, then send a response to the browser so that it can hide the camera UI and give a message.
In addition to inserting into the queue on hitting the page, also check to see if the user that is controlling the camera has had his 1min, if so then delete his record (or could be done on the cronjob below).
Each time the ajax poll fires, update the users last_update with a timestamp. Use a cronjob or just on the server side calls to check if any of the records in he queue have a last_update that is older than a short time, e.g. 30 seconds., if any are found then delete them because these are users that are no longer on the page. This will also prevent attackers trying to fill up your queue.
On the same cronjob, check if the user who's turn it is has the start_time populated, if after 30 seconds he hasn't started, delete from the queue.
The ajax calls would make it nice and seamless, but they aren't essential, if the user has Javascript disabled you can still detect that and use a meta refresh of the whole page instead.

Delete user from database if email not confirmed

I am currently working on a registration based website, and I have the server sending an activation email to the user upon registration. This is all done in PHP so, as you can imagine, I am using the mail() function.
This is all fine and dandy, once the user gets the email and clicks the activation link, the 'active' field that is in the 'Users' table is set to true. Here's the problem though, in the case that a user does not confirm their email address, what am I to do?
I have thought of holding details like the date and time the user registers but I don't know how to proceed with this data. How do I have the server automatically delete the user from the database after a set amount of time?
That's what I think I should be asking, but in all honesty I don't know the usual protocol...
Conclusion: Since Cron is for Unix based servers I've had to pass on it, but I found it very interesting that I could just use the Windows Task Scheduler that is built into Windows. This at least means I can test it on my PC before any server hosting. Thank you all
You should definitely store the date and time that the activation link was sent.
There isn't really a way to tell the server to automatically delete stale user data, but it's easy enough to code up yourself. Assuming you have access to cron on your server, you can set up a cronjob to run (for example) every night at 2am and execute a PHP script that searches the database for users who were sent a link more than X days ago but never confirmed it
i think the solution would be Storing the timestamp while sending the mail.
now run a cron every 15minutes which would check that which values are having timestamp more than 24hrs or any timelimit you want and then delete it from db
Just call in your index.php file the following code. (Why index.php ? - because it is requested every time and can "act" as a cronjob.)
(Just Pseudo Code - might need some tweaks!)
mysql_query("DELETE FROM user WHERE active = 'false' AND registerTime < (NOW-60*60*24*7)")
This will delete all Users which have not been activated within 7 Days.
It's just a concept idea i think you can build on.
You should look into cronjobs that you run daily. Simply put in a field in your database with the time your user registered.

How can I run an infinite loop on my website? (for a reminder/deadline announcer)

I'm building a website and i want to implement a reminder feature that alerts people if they have any projects or activities that are due or simply alert them of any timer they may have set. I have a clue about how i could do it with javascript's timer functions but i want it to run all the time and add reminders to a queue if the users are not online when the event occurs. Is there any way of doing this or do i have to use bash or python on the server?
Further explanation on how it's supposed to work:
- infinite loop checks for the time every X seconds, if there's a a reminder up between now and X seconds ago, print it to the user it belongs to - if the user is not online, put it in a file or something which is checked, when the user logs in, for any missed reminders.
another way i thought of is to use a local script (pyton or something) to check the database for reminders that are due, every X seconds, and write them in a file on the web server. then, server-side scripting will read it every X seconds and print the reminders to each logged account (and delete it at that point). This way no reminders are skipped even if the person it belongs to is logged out.
Any idea on how to do this more elegantly?
Use Cron Job instead and run your script with that to connect to your database and to do other tasks.
this functionality can be done with ajax and php. I wouldn't check the db when the user isn't online. I guess it is better to check reminders on login (unless you want to for example email them when they occur->then you need cron like mentioned in the other answers). you'll need to make a php script that checks which reminders have to be set and return them in an array/json. on login call this page. when user is logged in you can request your reminder php periodically/timer with ajax.
Having an infinite loop is by default bad design. PHP won't like it at all (memory). Javascript isn't ideal for the same reason too. Apart from that you don't want a javascript sleep to block your UI when waiting between tries.
Also, I wouldn't check notices when the user is not online. This is a useless way of using resources. Simply save the last time a user was online and display past notices that he hasn't seen before on login.
The cleanest solution in my book is some javascript library capable of eventdriven actions. An example of that is node.js. With events you don't need to check every N time but simply have an event triggered if some condition is met.

User-specific timer actions in a MySQL database

I have a database full of users and each user has timestamps for a specific events they've executed. I would like to fire off an action for each individual user based on their timestamps. So for example: user1 hasn't logged in for 5 days, send her an email or put her user status to "idle" mode.
What would be the best way about doing this?
I don't know if it's the best way but usually you setup cron jobs to that kind of things.
Your cron job would be a simple PHP script, it would query the database to find all the users that the system should process and send emails etc ...
If you are on windows the scheduled task should be a drop in replacement for cron jobs.

Categories