PDA

View Full Version : PHP Q



MrPinkPanther
22-07-2009, 07:33 AM
This should be my last question on PHP. If I have an application which POST's to PHP every 4 seconds is there a way that I can detect when they have stopped POSTing and have hence logged off? So say after 8 seconds they haven't posted anything so have quit the Browser or whatever.

Thanks in advance,
FlyDuo.

BoyBetterKnow
22-07-2009, 09:52 AM
This should be my last question on PHP. If I have an application which POST's to PHP every 4 seconds is there a way that I can detect when they have stopped POSTing and have hence logged off? So say after 8 seconds they haven't posted anything so have quit the Browser or whatever.

Thanks in advance,
FlyDuo.

Mr FlyDuo. I remember you saying that Actionscript PWNT php.

I'm trying to think of a good way to do this.

You could run a cron job every 10 seconds to check which users havn't posted in 10 seconds. Or you could do it so the thing that gets posted to, for instance if user A is logged off and user B is still online, the script that user B's browser is posting to could check if user A is still posting, but I wouldn't recommend that.

I'm thinking a cron job really. Depending on your potential user base really.

Source
22-07-2009, 10:04 AM
Stop using the word really, it's really annoying.... really. ^_-

I came across this issue a few days ago when I started making my collaborative viewing application (watching videos in a group/listening to audio together) but my circumstances are slightly different as I have a 'lobby' leader whom I use as the host.

Having a lobby leader allows me to use regular calls from his/her browser to check a timestamp of when they last made a post request, if it's higher then 20 seconds then I delete their entry from being in the lobby. Then I use a cron job every 5 minutes to see when lobby leaders have quit, just to clean things up. (Note: This is small scale, so I am not worrying about the extra overheads of using user script calls to check).

Presuming you don't have someone that's meant to be in with them at all times, probably best to run a cron job every 10 / 20 seconds.

Excellent2
22-07-2009, 10:05 AM
Do a cronjob, 10 seconds is a bit too much.

Source
22-07-2009, 10:07 AM
It may be too much, but he is trying to get it as close to real-time as possible. (I presume).

Plus the resources for running that wouldn't really be noticeable.

MrPinkPanther
22-07-2009, 10:10 AM
I know what a cronjob is but I haven't really used them really. I'm just really wondering how to do it really. Could anyone give me any help? It would really help me really.

Basically every user posts his own username to Online.php and I want to say: If(//user hasnt posted in 10 seconds){
//Do something with user
}

BoyBetterKnow
22-07-2009, 12:48 PM
Stop using the word really, it's really annoying.... really. ^_-

You really want me to stop using really ey?


I know what a cronjob is but I haven't really used them really. I'm just really wondering how to do it really. Could anyone give me any help? It would really help me really.

Basically every user posts his own username to Online.php and I want to say: If(//user hasnt posted in 10 seconds){
//Do something with user
}

I havn't used a cron job in a few years, but I believe you just put in a little bit of code for it to run, which includes the online.php page, and it runs it.

MrPinkPanther
22-07-2009, 01:12 PM
You really want me to stop using really ey?



I havn't used a cron job in a few years, but I believe you just put in a little bit of code for it to run, which includes the online.php page, and it runs it.

I've used cron jobs in the past for my Flash stuff but they've been more of a C&P job, I'm not sure how to create it myself.

Agnostic Bear
22-07-2009, 01:14 PM
If you're using mysql, just slap their name into an online table with the time they last refreshed and check with a simple WHERE `time` > '192382' or something.

BoyBetterKnow
22-07-2009, 01:16 PM
If you're using mysql, just slap their name into an online table with the time they last refreshed and check with a simple WHERE `time` > '192382' or something.

Yeh. To elaborate on what Jew Bear said, have a table called online and have the fields: userid, time.

Then you will have all your online users in there, and then remove the record if it's not online or whatever. This is opposed to some people who would have the online field in the users table which is not a good idea because the users table will have more to search from.

MrPinkPanther
22-07-2009, 01:43 PM
Unfortuantly I'm not using MySQL but its a nice idea and I think ill do a variation on that ;)

Excellent2
22-07-2009, 06:32 PM
Unfortuantly I'm not using MySQL but its a nice idea and I think ill do a variation on that ;)What are you using? Flat files?

Blob
22-07-2009, 06:55 PM
What are you using? Flat files?

Or MSSql, Firebird, or that thing cpanel supports that no one ever uses.

BoyBetterKnow
22-07-2009, 07:18 PM
Or MSSql, Firebird, or that thing cpanel supports that no one ever uses.

You thinking PostgreSQL or w/e ? I never touched that.

MrPinkPanther
22-07-2009, 07:31 PM
XML files well...Plists, which are essentially XML files.

Protege
22-07-2009, 07:51 PM
./online/username.txt

inside file, timestamp of last refresh basically

to check, open username.txt, check against time() with the timestamp recorded, and wala. You have jewbears thingy, its easy... really.

Dentafrice
29-07-2009, 01:51 AM
XML files well...Plists, which are essentially XML files.
I've always wondered why you are doing that, flat files.. and not via database.. why?

MrPinkPanther
31-07-2009, 03:05 PM
Ok, I'm really confused.

So I have all of these files in www.URL.com/<yourusername>/<yourusername>.plist

If <yourusername>.plist hasn't been updated in 12 seconds then I want to POST <yourusername> to removeUser.php. How would I go about doing this?

There are many users that I'd have to do it for so I'm not sure how to do it in cron jobs.

Invent
31-07-2009, 04:22 PM
Ok, I'm really confused.

So I have all of these files in www.URL.com/<yourusername>/<yourusername>.plist

If <yourusername>.plist hasn't been updated in 12 seconds then I want to POST <yourusername> to removeUser.php. How would I go about doing this?

There are many users that I'd have to do it for so I'm not sure how to do it in cron jobs.

Why are you using plists? Why not use something like MySQL? It'd make the solution a lot easier...

Dentafrice
31-07-2009, 07:10 PM
I'm wondering the same thing.. it's just going to be a lot of lag time and overhead if many users start to use it.

You can setup "virtual" plist files, and return the database results in XML format, if you're so dedicated to using XML, but still having the functionality, speed, and versatility of a database behind it..

I think that'd be a whole lot better solution.

MrPinkPanther
31-07-2009, 09:22 PM
Trust me .plist's are completely suitable for what I'm doing. I just need to know how to do what I posted in my last post ;). After that I'm sorted.

Dentafrice
01-08-2009, 02:07 AM
But the logic that we are having to provide you isn't suitable for what you're doing.

Want to hide these adverts? Register an account for free!