Reminder Pop up using php,jquery - php

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.

Related

How to send FB notification at specific time to different time zones using PHP SDK?

My website is relaying heavily on FB. There is only FB login and all comunication with members happens through facebook. Users are notified using FB api about activities in site that they would care about. Users can choose between three options:
Never notify
Notify once a day(for MVP version I am good with hardcoded time, lets say, 9 in moorning, but probably aiming for possability for user to choose when they want to be notified about everything that has happened in last 24h)
Notify on-the-go
First and third are easy, my concerns lies on second option. Basically its similar to newsletter. Here is my idea of this process so far:
When ever some action that is of concern for user happens, notification about that is saved in database
if user logs into site before scheduled time notification is marked as read
if user does not log into site before scheduled time unread notifications will be included in cron job
every hour cron job is run. It matches the users time zone with current time so that only only users that are awake will recive notification. Users will get basic "there are new things in site" notification.
Problem: From FB I can get only offset as integer, not actual timezone. I have spent some time on reading about timezone and different formats and it strikes me that FB call to get timezone results in offset.
Sending newletter(notification in my case) to different time zones is complex but there are a lot of good resource available. However it seems that best way to do that is save user time zone as TZ database format America/New_York. So my question is dual
Is it possible to somehow get user time zone in TZ from facebook?
If not, what would be my best actions? Whats important is that I dont care if user dont get notification at exact time. With that I mean that I dont care about summer time difference. it would be ok if user could chose between moorning, afternoon and evening(and if for example he chooses moorning, then he would get notification 9:00 +/- 1 hour). I am open to ideas, at given point my main consern is to get MVP running.
$ch = curl_init("https://graph.facebook.com/v2.6/" . $user_id . "?fields=timezone&access_token=" . $fb_access_token);
curl_setopt_array($ch, array(
CURLOPT_RETURNTRANSFER => 1
));
$result = curl_exec($ch);
You can get the user timezone from the open graph api.
For converting the offset to an actual timezone see the answer here: Convert UTC offset to timezone or date

Browser game PHP+MySQL increasing resource every second

I'm create a small browser game and I'm programming the resource handler.
I'm using PHP and MySQL database.
I realised that I can't update the database every second to increase my resources, so reading on Stackoverflow, I found this post:
I am also trying to make a online game in PHP and encounter also this
problem. My solution was actualy pretty simple. In Assuming you are
using different city's or planets, you will need a database table for
the city/planet. In this database you store the current resources and
the resources per hour. And also a timestamp.
For upgrading resources facility (gold mine for example) i have a
database that has all the building ques with a begin time and end
time.
i then have made a page that i include on every page in the game. It
first checks if there
are any building ques for the selected city that
should be finished since last time database was entered. If that gold
mine was finished at let say 12.00 and the timestamp on your city was
11.00 and current time is 13.00. What the page does, it calculates all the resources for the time 11.00 to 12.00. Then it will update the
gold per hour in the city table. And then it recalculates the
resources from 12.00 to 13.00.
when all the above is done, it puts the timestamp on current. But as
you have all the resources per hour from the second run, you can store
it in an array and let a local timer run to update the resources on
screen. But since you include the above mentioned page on every page,
when you go to the next page it will acces the database to see what
the current resources should be. So the local data is only for
viewing.
By DutchEcho
This is the link: LINK
I programmed the events queue and everything is fine. The problem, now, is to increase the resource if the player is online.
If I save the last_login of the player by time() and then I calculate the new amount of production I have a problem:
"UPDATE `stats` SET `rock` = `rock`+(('".time()."' - $last_login)*$rock_production)
I do: time() - $last_login. If I save the last_login every time a player reloads or changes page, this difference will be always 0.
Because the two times are equal.
How can I increase my resource every second?
Rather than updating last_login on each page load, only update when you start a session. You might have a second field that you update on each page load, and use the difference for your calculation. The two fields could also be used to indicate the duration of the most recent "time on line" even after the user disconnects.
[edit]:
How about using an update trigger? In a single statement you would have both values of last_login available - the new value and the original value.

PHP deadline notification

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?

Get dynamic time and timeout after certain amount of time

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.

How to handle user online status when he/she close the browser?

I am having table to track user online status by setting 'is_online' field to 1. Now User get logged in the site and shut down his/her system or power down at that time he/she logged in.
Here in database 'is_login' has the value '1' which means he is still using the site.
So I have to do some logic to change that value to '0'.
How can i handle this situation using PHP ?
The normal solution is to store a timestamp in the table which you update every time the user does something. Users with a recent timestamp (say, five minutes) are shown as logged in, everybody else are logged out.
It doesn't even have to be updated on every page load. Keep a timestamp in the session with the last update time as well, and only update the table when the database flag are about to expire.
Store an time-since-last-activity. When it's been longer then a specified time - treat as if offline. You should replace the is_online with an DateTime field, and update it every time the logged in user visits the website.
On the place you want to select all online users, instead of :
SELECT * FROM users WHERE is_online = 1
You could use:
SELECT * FROM users WHERE is_online >= DATE_SUB(NOW(), INTERVAL 5 MINUTE)
you can't. HTTP closes the connection once the page has been delivered. On the server side alone all you could do is checking if a user has requested a page within a certain amount of time.
JavaScript might be your friend. You could use it to create a ping to a php script which then updates the last request timestamp. Once there is no more pinging, the user is gone and you'd know.
If you have trouble with javaScript, a good point to start would be here: http://www.w3schools.com/JS/
You might want to focus on the AJAX and HTTP request stuff.
cu
Roman
You can use jquery to update your site each X time, so a function is executed each 10 seconds, as following code:
function updateTheBBDD(){
... calling mysql_connect -> mysql_insert -> mysql_close
}
setInterval("updateTheBBDD()",10000);
Also, when painting the user status monitor instead of consulting the BD and:
1->green
0->red
You should:
actual - time > 10 ---> red
actual - time <= 10 ---> green
Due to the stateless nature of the web it is not possible to know exactly when the user left your website. So you can't really trigger any code to change the mentioned value.
As the other have said one has to store the time-since-last-activity to get an approximate idea when was the last time the user was actually doing something with the website.
HTH :)

Categories