I need to create a system that can store documents, those documents are jobs due to specific dates so this system should send an email notification to the admin to notify him/her when a due date for a specific document is near.
Basically i have no problem at all, apart from one single very important point: the notification system should work without user intervention. I can easily trigger php scripts on each page visit but i do not want that. This case would be quite "easy", i would just set a date for each document in the sql row and each time the page is visited a php script would check if the current time is near the time set in the sql row for the document. But this needs the page to be visited.
Suppose my client sets a due date for a document and then never visits the site again, how can it happen that a php scripts automatically fires itself to perform the necessary checks to see if there are due dates in the upcoming days?
Thanks in advance
Why not use MySQL Event schedular?
Related
Show reminder pop-up for one customer based on the follow-up time reached for customers.
Scenario
I have 10 customers, i have set follow-up date and time for those customers between 10 am to 5 pm on today. If any customer's follow up date and time is reached that time will show pop-up with their details.
Performance Issue
Normally, This event will trigger, when the date and time is reached that time only trigger, So every second we should check the server time with corresponding tables. So If we check this kind of matching data in DB, definitely we should face performance/Lock issue.
How can be this done with efficiency using php, jquery or any other tools??
The same logic you can apply with a small modification.
Take the server time from the server and at the same time take all user ids and their follow-up date and time who all having the follow-up date and time in the same day (or all if there are no more no of users) and store it in client side (Cookie or local storage).
So every time you can check the date time(Take server time stored in client side cookie as reference) in the client side itself and if there is any match occurs only you7 need to make a call to the server side in order to take the corresponding details.
I'll try to explain my question the best way I can.
I'm not asking for codes, only for the best method of doing it.
I want to create a browser game and use time for upgrading stuff, building etc.
For example, to build 1 house will take 1 hour.
So I will began with saving the timestamp+(60*60) at the moment the user did his action.
My question is, how to update it the best way?
One way I thought of was to add function that check every page view of the user if it's done.
But then if he's not logged in the update wont happen.
Second way i thought about is for every page view of any user to check for every user registered. But it's not effective and there is a problem if no user is logged in.
Any suggestions?
I had my game doing it simply, without crons.
When a player wanted something that takes time, i just updated his database information with the appropriate time of ending that job (columns are just examples)
UPDATE player SET jobend = UNIX_TIMESTAMP() + (60*60*4) # ending in 4 hours
Then, every page that had an information about the remaining time, i just used something like this:
SELECT (jobend - UNIX_TIMESTAMP()) AS jobremaining FROM player
I formatted correctly the time using strftime and i displayed that to the user.
In the case the remaining time was negative, the job was done.
There was no-need for absolute counting since user was able to do something with the job when he was connected.
When the player just changed pages or doing something else i had a function where i just checked all timely events while the user was online (so to catch any negative timer), then presented with javascript any change (i posted javascript counters for every page)
Now, if you talk about updating in real-time, cron is the way but are you sure you're going to need it for a game? I asked that question myself too and the answer was not.
EDIT
If another player sees the buildings on schedule page (an hypothetical page) i am doing the same calculations; if a time just got negative for a specific player (regardless if another player see the page), i just reward him with the building (in database i make all the changes), even if he's offline. There's no harm in this, since he can't do anything anyway. The other players will just see he has a building. The key here is that i execute the required updating PHP code regardless of player's connection to the game; as long at least ONE player is logged-in i'm executing the progress function for everything.
This isn't so slow as it sounds (updating all players by using just a connected player that visits a specific page). You just have a table of 'jobs' and check timers against the current time. More like a single query of getting the negative ones.
I have an inline chat application which I got from Ajax Chat, which is working brilliantly. The application allows a user to chat with users that are registered on the system. Ie:
Now I need to show if the user is online or offline.
So my question is how do I show online users using PHP?
Thank You
Basically what you need is a way to register users activity.
One way you can do this is doing it by sessions within PHP, and you log these. There are tons of ways to register then your activity in a log. If the activity is not updated for example in 5 minutes, the user is offline. Bassically you just need then a sessionId, and a timestamp (and i would recommend this also to hang to a userid). If offline, there is no userId assigned and when online you add a userId. If you have those, its pretty easy. Its a matter of updating them constantly when a new page is loaded and if they log out, you simply destroy the session, or update it so it wont be linked to the user.
It may not be the best system, but it works, and it might help you.
I don't know your specific needs. Pardon me, If I am wrong.
If Jabber support is there with Ajax Chat, why not try ejabberd kind of XMPP servers rather than re-inventing the wheels on your own. And you could have a look at Apache Vysper too, since it has support of extension modules too. If XMPP server is there, users presence handling and message transfer would become a cake walk.
What you need is a constantly update for a table in your database that save the last change in an user and save the date time... so if that date is more than 5 or 10 min, the user ir off..you can do it with ajax...
What i would do is have a script that the clients run to do an ajax call to update a entry in your database with a time stamp for last seen. Not too often or you will overload your server.
you can also put some if statements where it checks for keystrokes, mouse movement, and if the window is active if you really want to get technical and do a away status.
then in active chats just check the time stamp for active messages or when the user list is open. anything outside a acceptable range will show the user as off line. 5 minutes seems pretty long to me. poll for a check every 10 seconds maybe?
I am implementing an online exam portal, so that a user can start the mockup test(exam) and choose the anwsers for each question and proceed to the next question.
Rules for the exam is to give 100question to complete in 75mins.
So I need my back-end code to check each bit of time and track if the current_time not exceed 75min from the Exam_Start_time
How is this possible.
I made it like this for time being
$Start_time
$Current_time
and then check the difference on each page refresh and redirect if 75min limit exceed
But I think its not the better way and if we can trace it dynamically and redirect when the 75min mark reaches to the process the exam result it would be great.
Can any one help me in this context,
Is there a way if its not possible with PHP, HTML to use Javascript to achieve this
Hope to hear from you stacker.....thanks in advances
Store in your database time and some unique id for each user. While user take a test send ajax request with some interval (i.e per minute) to the server with user unique id and check is everything ok with time if not redirect him to another page or block old one with javascript. But think about security, some user can guess and send another's id :)
If user disable javascript there is another scenario. Server closes tests which hasn't been updated for some interval. And also about local time and javascript you haven't to send user's time to server because you have start time in database.
#trejder and #Wiz if think as you do it's better to do not use javascript at all as it can be turned off and request variables can be falsified by user.
i m creating two table(in mysql) named
table_temp_guest
table_temp_order
now if a guest enters then we save his personal information in this first table and if he purchase something from any stall ,it saved as a temporary order in table_temp_order.
now my question is :
i m using session id, so when user goes to logout( without checkout) then
i delete his information(personal and order) from both table )using session id,
BUT if he close the browser, or does not go to checkout(any reson) then how
to delete his information from both tables
please suggest me how to do this?
additional question:
is there any other way to do this whole process by some other manner.
You can't detect when a user closes the browser or types in a new address. You basically need to have a "timeout" facility like the rest of the websites have.
There is a window.onunload event that you can detect with javascript, but it's not universally supported, and it detects window closes, not browser closes.
Your best resolution is probably going to be tracking the session_id and last accessed date. Re-update the table's last_accessed_date on every page load, and delete everything that's older than a few hours.
A timeout would be the best method.
Record the last active time in the guest table. Have a cron job running periodically on the web server cleaning up sessions that exceed the maximum time that you wish to allow.
Be careful about the amount of time that you allow. You have to allow for slow users and dropped connections.
If you're using session_id() anyway (I guess this is what you mean by session id), just use php sessions. PHP automatically invalidates them for you and you don't need those two tables (you can store everything you need in $_SESSION).
There is no way to check if the broswer wasn't closed you could rely on.
If you don't want to change the way your project works now, just add a created field to the tables and set it to the current time() whenever you're "seeing" the specific user. Then set up a cronjob which deletes all records from this table which are older than a specific timeout.
Also you can try to have a script that would run on the client side and ping the server so that you know if the script has not pinged for a while, the user closed the browser. That being said, I would agree with the previous posters, a timeout/ cleanup procedure would be best.
For that you would add a ModifiedDate field to your tables, you can set it as an "ON UPDATE" field for ease of use, then just delete all records that have an ModifiedDate field of older then several hours.