How to send a message to a specific logged in User.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
asterinex
Forum Commoner
Posts: 52
Joined: Thu Nov 25, 2004 7:01 am
Location: Belgium

How to send a message to a specific logged in User.

Post by asterinex »

Hello,


I have the following problem :

I have a website where different users can log in. Some users can be friends of eachother.
for example if John is online and Frank (his friends) logs in . I want a tekst to appear only on John´s screen "Hey John ... Frank is online".

Anyone any suggestions how to do this ?

Thanks
User avatar
MarK (CZ)
Forum Contributor
Posts: 239
Joined: Tue Apr 13, 2004 12:51 am
Location: Prague (CZ) / Vienna (A)
Contact:

Post by MarK (CZ) »

You'd have to store who's friend of whom in db and then something like:

Code: Select all

$sql = "SELECT users.name FROM users, friends ". // get names of active users
  "WHERE users.time > '".(Time()-300)."' ".      // only those who were active in past 5 minutes
  "AND users.id = friends.friend_id ".           // only those who are set as friends
  "AND friends.user_id = '$userID'";
I hope I didn't make an error :)
asterinex
Forum Commoner
Posts: 52
Joined: Thu Nov 25, 2004 7:01 am
Location: Belgium

Post by asterinex »

YO Thanks,

looks good.
Do you think you could put the code in a small frame with a auto-refresh?
User avatar
MarK (CZ)
Forum Contributor
Posts: 239
Joined: Tue Apr 13, 2004 12:51 am
Location: Prague (CZ) / Vienna (A)
Contact:

Post by MarK (CZ) »

Why not :)

It's just important to log time of last user action to keep this info about online friends up-to-date (so not only logging of user's log-in but also other actions - otherwise user active for more than 10 minutes would act as inactive).
asterinex
Forum Commoner
Posts: 52
Joined: Thu Nov 25, 2004 7:01 am
Location: Belgium

Post by asterinex »

OK, Gonna try it ?

One Question regarding performance.

How much requests can a SQL Database handle. If fe 500 USERS are online and each have an auto-refesh to query the database . Can de SQL Database handle such Traffic? What Problems can occur ?
Archy
Forum Contributor
Posts: 129
Joined: Fri Jun 18, 2004 2:25 pm
Location: USA

Post by Archy »

Depends how often the page refreshes; it it were to refresh every one or two minutes, then it generally shouldnt be too bad on the database. Every 10 seconds may make the database strain a little bit if all those users were online.
asterinex
Forum Commoner
Posts: 52
Joined: Thu Nov 25, 2004 7:01 am
Location: Belgium

Post by asterinex »

Ok thanks "Just a little bit" Sounds good ! I guess , I have to trie it out !



Thanks eveyone
Post Reply