0

I am creating a web application named Online Exam using PHP+MySQL and AngularJS. Now I am getting some trouble on project like changing the user looged in status. Let us take this condition as a example:

  1. Suppose a authorized user/student successfully logged in online exam section(After successfully logged current time will be inserted in the db in exam_start_time column as unix timestamp format and exam_status will be set as 'ACTIVE`.
  2. 1hr(60 min) countdown timer is initialize for him/her as per the inserted exam_start_time in db.
  3. Now suppose after 15 min the system shuts down automatically, then if user logged in again(In same system or other) then the countdown timer should be set for 45 minutes only.
  4. Previously I was updating the last_activity_time in our table in every 10 sec(using ajax calls). but now I want to change this way, Is there any way like(socket or network programming using PHP) to update the column.

Here is my table structure which is managing user logged in status

enter image description here

Please give me some suggestions on it.

Anil Kumar Pandey
  • 1,877
  • 4
  • 27
  • 44

2 Answers2

0

A Php socket server programming tutorial : http://www.christophh.net/2012/07/24/php-socket-programming/

Pascal Le Merrer
  • 5,883
  • 20
  • 35
  • Thanks for the links, I haven't used socket in php+mysql, so it would be great if you refer some links which is updating the mysql table by using socket calls and one more question for you, Is `socket server programing` will also run on intranet? – Anil Kumar Pandey Jul 10 '14 at 06:46
  • It likely should work. The only case I'm thinking that could prevent this to work is if there was a network equipment (proxy, firewall...) that do not accept communications on the port you will use. But this kind of equipment is usually located between the Intranet and the Internet, not inside an Intranet. – Pascal Le Merrer Jul 12 '14 at 07:13
0

Sockets, as Pascal Le Merrer mentioned, is IMO your best option. But beware of Apache! Every WebSocket holds one Apache thread, and Apache wasn't designed to do that. when too many (and by too many I mean few dozen) clients connect to your site, it will crash. (I've been there while trying to implement long polling/comet, ended up using NodeJS. If you're using nginx, it is more likely that it will become low on resources and effective, but there are also other ways. Take a look here: Using WebSocket on Apache server

If you find this uncomfortable/hard to learn, try also another idea: try to add hidden iFrame to your exam page, pointing to prepared site that updates database row. Use javascript to refresh this page every 10-15 seconds. Every refresh causes update of specific row in DB, using current date and time. It should work (not tested, but give it a try).

Community
  • 1
  • 1
ex3v
  • 3,518
  • 4
  • 33
  • 55
  • Thanks for so many options, Yes I am using xampp(Apache), but I can move on to `nginx` so please give me some example on the same(MySQL connection with DB updation related resource or links would be more useful for me) – Anil Kumar Pandey Jul 10 '14 at 07:05
  • There are plenty on google! ;) Here's one, quite interesting: http://socketo.me/docs/hello-world It might hard at the beginning, but you should give a try, and also (probably) learn something new. This example is even more interesting because, as far as I understand, it doesn't require ANY web server. – ex3v Jul 10 '14 at 07:29