Can PHP tell if someone is typing?

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
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Can PHP tell if someone is typing?

Post 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
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Can PHP tell if someone is typing?

Post 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.
phphelpme
Forum Contributor
Posts: 261
Joined: Sun Nov 21, 2010 3:32 pm

Re: Can PHP tell if someone is typing?

Post 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
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Can PHP tell if someone is typing?

Post 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.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
genix2011
Forum Commoner
Posts: 74
Joined: Tue Aug 02, 2011 4:00 pm

Re: Can PHP tell if someone is typing?

Post 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.
Post Reply