Throdne
Throdne

Reputation: 619

PHP pushing data to the client without fetching

I was just watching a ajax/php web chat client video from phpacademy (Link to the youtube videos) and I had a question about pushing and fetching. In the video they fetched the data from the MySQL database every second or so.

But my question is, is there anyway to push the chat to other connected users rather than fetching it? With the application I'm developing, It would be a lot of requests on the server and be a waste of bandwidth.

But I still want it to be as basic as the ajax/php chat system. What I'm developing is a turn base game and the idea/code behind the chat system is exactly what I'm looking for. But instead of sending a text message it might send a score, move, and/or time, etc. and having it fetch wouldn't be ideal for the server when there maybe multiple people connected.

thanks for the comments and answers.

Upvotes: 0

Views: 1006

Answers (3)

Jefferson Javier
Jefferson Javier

Reputation: 317

in javascript you may use setInterval('Messages()', 8000); for get news messages in your db EVERY 8 SECS, if this is true you show them.

Upvotes: 0

Aaran McGuire
Aaran McGuire

Reputation: 3225

It sounds like your after something like Socket.io, or if you cant set that up you could use http://pusher.com/

Upvotes: 2

1321941
1321941

Reputation: 2180

No, with php it cannot be done, as php is a server side technology.

However, you should have a look at WebRTC as it allows P2P connections and is perfect for your use case.

Upvotes: 0

Related Questions