I am trying to create an Online Quiz script like expert rating test on ODesk or Elance.
I want to track the time, means how much time have passed and left. I also want to stop the time counter, if the user internet connection is disconnected, so that he can start from where it was disconnected.
One last thing how to disable the last questions, which were attempted by the user. I am using PHP, MySql for it.
Your ideas will be great help for me.
Thanks in Advance
I've done something like this. Basically you have the right starting idea. Create a timer table which stores start times, test id and user id.
On each page load or AJax call you check the current timestamp minus the start time to see how long has gone since they started. If at any point it passes your limit you redirect them to the test complete page. Don't worry about the internet connection its actually irrelevant. This basic rule covers all.
I've done something related to this. you have to think about this to begin the idea. Create a timetable that stores begin the time, user id, or testing id.
Related
I have made an employee management system as such, and it calcualtes leave days. Although I am trying to work out how to make the leave days update yearly according to the staffs starting date.
I think I know how I will do this easily. Except it will involve the software being open on that date.
How would I account for each day, without the software having to be open?
Heres the process i was thinking:
-Loop through array of staff data and determine if starting date matches current date.
-If it matches then add an ammount of days to their leave days
I know this is very basic, and it has some flaws. Here are the flaws i am thinking:
-If the page were to be refreshed, or page opened again then it would add x2 of the staff days.
-Also, if the software was not to be opened on this day then the staff would not get the added leave days.
How would I get around this issues? I feel like it should be an easy thing, but I cant think on how to do it properly.
Any help would be greatly appreciated,
Create your php script I'll call it leavetime.php
Then if you have c-panel on your server, there is a thing called cron, in there you can select the time to call it. typically it will be something like this for the command
usr/bin/php -q locationof/leavetime.php
https://www.youtube.com/watch?v=ZAbefcWLxrw
As for the actual php code to do this, it's to broad a topic to cover in a single question.
I'm working on a basic lamp(willing to change) website , and I currently need a way to run some function on the server that runs for several hours per user, and every X hours it needs to query the mysql database to see if the value for that user has been updated, if it hasn't it need it to insert a new record in the database...I also should mention that the 'every X hours' can change per user too, and the total runtime of the function per user can also vary.
So basically I need a function that runs continuously on the server for few hours per user. What is the best way to do this? I want the site to be able to support many users (like 10000 +).
I'm willing to try new technologies for every aspect of the site, I'm still in the design phase and I was looking for some input.
I've looked at cron but not really sure how well it would work when dealing with so many users...
edit: Here is a typical scenario of events;
User presses button on the website and closes the browser.
Server starts a timer from when they pressed the button, now
the server will check if that user has pressed a different button within a given time frame (time frame can change per user), say within 30 minutes. If they didn't press the other button then the server needs to automatically insert a new record in the database.
The script will need to continue running, checking every 30 mins for say the next 5 hours.
Thank you!
Cron would work as well as you can code the page it will run. It's not a cron limitation.
The question is ambiguous btw. Maybe explaining your full scenario would help.
Meanwhile, my suggestion would be to set up a scrip that allows you to manually check what you need to check.
You definitely need the DB to be InnoDB optimized with proper indexes to be able to support 1000 plus users.
To alleviate the number of calls to the database, a common practice is to run scripts only on what you are interested (so in the case of users you would only select those who have logged on in say the past 3 hours)
That's achievable in 2 ways, a simple select statement, or by adding entries to a specific table on the login page, and remove them after the automated script has finished running.
All of this is pure theory without understanding exactly what you need to do though.
You are telling what/how you want to do, but not why you want to do it. Maybe letting us know why could lead to a different how ;)
However, what you can do is still use cron (or anything similar). The trick is to have
a last_interaction timestamp column
a maximum_interval column
a daily_runtime column
in your users database. Not optimized but you are in the design phase so you shouldn't pay too much attention to the performance aspect (except is explicitly required).
Basically i just want to know if i have the right idea or if a better one exists.
I have a database that stores auctions that are currently taking place on the website (or will do). Obviously there comes a point when the auction will end. I am pretty new to web developing and was just wondering the best way of changing the status of the auction in the database to "expired".
I am using phpmyadmin and mysql and have read a bit about mysql event schedulers. From what i can gather they seem like a good way of doing this. On this basis i surely just run a recurrent event every minute, say, and it checks the current time against the preordained finish time of the auction and then makes changes if need be? Is this correct? Also i can then move the expired auctions to an old archive - probably the best right idea do you think for optimum performance of my database?
Otherwise i just wondered if there was a better (or easier way) of doing the same thing. How do sites like ebay go about it for example? Thanks a lot for your time in advance.
P.S. I realize this is more of a conceptual question then anything specific. Nevertheless i hope its alright to ask!
You're way overcomplicating this. You don't need to actually change the status of the auction the moment it expires. The status is self-explanatory already from its expiry date. If you have a column expiry_time in the database, any time before that the auction is active, any time after it's expired. As simple as that. Use appropriate queries, like this to find all active auctions:
SELECT * FROM `auctions` WHERE `expiry_time` > NOW()
You could do it this way, but I would suggest another approach. This is something I've implemented myself (in a game, but with the same mechanics), and it worked like a charm.
The only thing you have to do is to run a function at every pageload (before anything else) and check if anything needs to be moved to the archive. If anything needs to be taken care of, do it.
If you do it this way, you know that the page the visitors are seeing always is updated. If you use some sort of cron_job or event like you talked about, some of those auctions might be "expired" a few seconds after the job is executed and is therefore displayed as incorrectly active for almost another minute.
I've decided to create a web based chat system for the experience. I'm using a mixture of AJAX(jQuery), PHP, and JSON to transfer the data. Now that I've started thinking about certain things, I've come to a mind block.
Right now, I use javascript to post the last loaded message id to a php file that queries the data and echoes new posts in json and then displays those posts in order on the page. However, the dates don't reflect the current time for the user. Since I use php to get the current time, I have no idea how to display the correct time to the user which takes into account of their time zone. Second, how would I incorporate a who's online list with this method? I could create a separate table and update it when a user creates a session and delete their name when they end the session; but what if they don't close it properly? Should I just add their last sent message into the the table and if it's been about 5 minutes since their last message consider the user disconnected? Lastly, is the method I'm using to collect new posts efficient? This there a better way to go about this? I appreciate any input.
This seems related: Determine a User's Timezone
I'm going to make you go there for the code snip so you give proper credit with your upvotes.
I get the impression that Javascript is the best/easiest way to get that data.
What I would probably do is use GMT or some other fixed time zone for all your server stuff and then just adjust that with js once it hits the browser depending on their time zone. Either that or just collect it once at the start of the conversation and adjust your output accordingly. There might be advantages to either way.
Edit:
Oh yeah, about the "who's online" I think you're headed in the right direction. I might suggest 2 lists. "Who's active" and "Who was active recently"
That way you can put people inactive after 5 mins and consider them disconnected after 10 or something. I guess it's about the same but it seems more accurate to me somehow.
The other option would be to set an ajax request to automatically fire of a request every minute or so. When they stop then you know the user is gone.
I need a way to modify a value in a table after a certain amount of time has passed. My current method is as follow:
insert end time for wait period in table
when a user loads a page requesting the value to be changed, check to see if current >= end time
if it is, change the value and remove the end time field, if it isn't, do nothing
This is going to be a major feature on the site, and so efficiency is the key; with that in mind, you can probably see the problem with how I'm doing it. That same chunk of code is going to be called every time someone access a page that needs the information.
Any suggestions for improvements or better methods would be greatly appreciated, preferably in php or perl.
In response to cron job answers:
Thanks, and I'd like to do something like that if possible, but hosts limits are the problem. Since this is a major part of the app, it can't be limited.
why not use a cron to update this information behind the scenes? that way you offload the checks on each page hit, and can actually schedule the timing to meet your app's requirements.
Your solution sounds very logical, since you don't have access to cron. Another way could be storing the value in a file, and the next time the page is loaded check when it was last modified (filemtime("checkfile.txt")), and decide if it needs modifying again. You should test performance for both methods.
Can you use a cron job to check each field in the database periodically and update that way?
A big part of this is how frequently the updates are required. A lot of shared hosts limit the frequency of cron checks, for example no more than every 15 minutes, which could affect the application.
You could use a trigger of some sort on each page load. I really have no idea how that would affect performance but maybe somebody else can shed some light.
If performance really starts to be an issue, (which means a lot more than you probably realize) you could use memchached to store the info...