Page 1 of 1

Can PHP tell if someone is typing?

Posted: Thu Sep 01, 2011 4:30 pm
by simonmlewis
I've seen on Facebook where if your friend types in the Chat, you are told they are typing.

I've seen it on various CHAT services where you are told if they are chatting.

How is this done? As they are on separate browsers. I am working on something where this function would be rather useful.

Many thanks

Re: Can PHP tell if someone is typing?

Posted: Thu Sep 01, 2011 6:26 pm
by twinedev
PHP itself cannot tell this. It is completely executed on the server. To accomplish this, you need to use AJAX that monitors the input and sends requests back to the server and tracks the status somehow. It also needs periodically check back with the server to get the status from other people to indicate if they are typing or not.

Keep in mind things like server load. If you have 5 people, even if it is only doing the requests only every 30 seconds, that is 20 requests PER MINUTE to the server (and that many calls to resources that are tracking status, ie database calls, etc)

This is why I always outsource chat services to 3rds parties that are designed to handle it.

Re: Can PHP tell if someone is typing?

Posted: Fri Sep 02, 2011 3:22 am
by phphelpme
Thats good advice twinedev, and you are right to outsource that need because even the larger companies such as BT, O2, Vodaphone, etc etc outsource this.

It does depend on your actual projected use of this requirement because if you know you are only going to have say 5 people max using it then you could handle those requests. But if your goals are to get more and more people using it such as Messenger, Skype etc then you make a choice of whether to get your own large servers or outsource.

Best wishes

Re: Can PHP tell if someone is typing?

Posted: Fri Sep 02, 2011 3:27 am
by simonmlewis
We don't think the demand will be high.
The thing is, I can use Ajax to do all sorts of things, but how do you use 'keydown' on one persons client-side browser, and then show "Fred is typing..." on the other persons?

If would be useful to at least try it. If demand gets high, then we can withdraw it.

Re: Can PHP tell if someone is typing?

Posted: Fri Sep 02, 2011 4:07 am
by genix2011
Hi,

Facebook is using an Ajax technique called COMET, which holds the HTTP connection to the server as long as possible, to accomplish this.

Greets.