0

i have developing a website that user can chat with other user if they are online . if one user send a message will notify that receiver on their screen , these checking process are happen in background process , i have an option of using

setinterval method and javascript self execution method

but i am looking much faster background process methods which will check every seconds if message or notification arrived .

could any one give suggestion for this.

4
  • 1
    Do you absolutely have to use PHP? If not, check out Node with socket.io. For these kinds of things it will greatly simplify your life. Commented Oct 14, 2014 at 6:05
  • for php you can use long polling technique but again, as @HeadCode suggested if you can use node js would be good solution. Commented Oct 14, 2014 at 6:19
  • You can also use websockets with PHP, no need for Node.js if you can't run it. Commented Oct 14, 2014 at 6:23
  • could you please share any sample examples of this , we using cakephp with aws serer..... Commented Oct 14, 2014 at 6:40

3 Answers 3

2

You can use HTML5 websockets.

WebSockets is an advanced technology that makes it possible to open an interactive communication session between the user's browser and a server. With this API(JS functions), you can send messages to a server and receive event-driven responses without having to poll the server for a reply.

below is good link to start

http://www.sanwebe.com/2013/05/chat-using-websocket-php-socket

Sign up to request clarification or add additional context in comments.

5 Comments

but my question is how i notify the receiver if he receives new message from another user ... like skype if the user sends they display a notification .
Again HTML5 will help you. You can use html5 notification api. see demo link (developer.cdn.mozilla.net/media/uploads/demos/e/l/elfoxero/…)
nice one thanks.... but it asks for permission from user , but i have to show the notification dynamically if its received.
It seems only way is to ask user for permission without it it is not possible to show notification.
here is more nice info on permission :paulund.co.uk/html5-notifications (see: Get Permissions To Display Alert in this page)
0

I think the best match for your needs will be http://elephant.io

Elephant.io provides a socket.io client fully written in PHP that should be usable everywhere in your project.

1 Comment

A note for OP: elephant.io will still require node.js.
0

Take a look at the Thruway Project. It's a PHP websocket implementation using the WAMP protocol, which gives you Publish and Subscribe abilities (you can use that for your chat application) as well as RPC.

A good place to start would to take a look at this chat demo (source code) and then use Thruway as the WAMP router.

I'm one of the developers of the thruway project, so if you run into any issues or have any questions, feel free to ask.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.