Jump to content

Recommended Posts

I'm working on a chat using basic textarea input, post, but the problem that I'm facing is, if a person doesn't send something, then the output is not updated eg. other messages from other users updating in real time.

 

How is that achieved when you see new database entries pop up live, milliseconds after they are entered?

Do I set a constant refresh rate of some sort?

 

How do you update a section of a webpage without "refreshing" the entire page like the POST method?

Link to comment
https://forums.phpfreaks.com/topic/293905-real-time-chat-databse-output-update/
Share on other sites

A "refresh rate" sucks, but is easy to implement. If the chat is slow, like a message every few seconds, then that might work for you. You actually do it with Javascript/AJAX so there's no literal refreshing.

 

More modern is WebSockets: you establish a dedicated, persistent connection between you and the client's browser and the two of you can trade information however you see fit. Couple downsides though. A persistent connection ties up resources on your end and can cause problems, especially on a "limited" or otherwise shared hosting server. It's also a bit harder to implement since it's not built into most web servers and PHP.

Before WebSockets was Flash and Java, which do basically the same thing (but only for the client half).

Hmm... that sucks

 

 

I'll have to look into each scenario

 

I have a VPS at the moment but ideally I would have a dedicated server

 

 

You actually do it with Javascript/AJAX so there's no literal refreshing.

 

Was that following the sentence prior or are you saying this is the normal solution?

 

I think the key thing for me to figure out is how to update components of a webpage without refreshing the page... I think this sounds like javascript eg. getElementId

 

I thought about a "if one user hits post, refresh all of the connected-user's webpages" hahaha sounds bad

Edited by moose-en-a-gant

Was that following the sentence prior or are you saying this is the normal solution?

I wouldn't call it the "normal solution" but it is cheap and easy to do. A good start.

 

I think the key thing for me to figure out is how to update components of a webpage without refreshing the page... I think this sounds like javascript eg. getElementId

Yup. You'll find all this a lot easier to do with a Javascript library like jQuery.

 

I thought about a "if one user hits post, refresh all of the connected-user's webpages" hahaha sounds bad

Actually it's quite a reasonable idea, but it comes with a problem: how do you tell the connected users that they need to refresh? And if you can tell them to refresh, why not just tell them about the new post instead? Edited by requinix
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.