Jump to content

Recommended Posts

Hi everyone,

 

Just wondering if coding a realtime chat room solely in PHP is viable? I know most use Java, but I can't learn that and the free ones have too many limitations.

 

By realtime I mean that what you type in the box appears instantly on the screen along with other users input.

 

I'm not asking for anybody to do it for me, etc., just as to whether it's possible but incredibly hard, or just impossible altogether.

 

Thanks.

Not possible without a combination oh PHP and Javascript (Ajax)

 

You would need to use the Ajax to constantly poll the server for chat updates, PHP cant do this alone because it's server side and has no direct interaction with the browser.

Basically, php alone is executed once per page refresh. That means that you can't run a php script without refreshing the page. Here comes as an aid javascript in it's known form ajax. This can be done with an ajax periodic updater, which checks periodically if there is any message. It should run a php script in the backend (asynchronously) that queries the database (sql or flat file) and prints the messages. As i'm no javascript expert, I usually like to have things easy in that subject, so that's why I usually use the Prototype (together with script.aculo.us for effects) javascript framework. It has some really neat and easy methods for easy ajax development. Give it a try, i'm sure you'll get the hand really fast.

Thanks for the info, I had a feeling it wouldn't be possible with PHP alone. Sorry for being dim, but I really do know nothing about javascript and the like...what is the framework for? Is it for offline testing, etc?

 

I think there's a big learning curve ahead of me.

If you look into socket connections you can actually do this without a heavy database back end.

 

You make a system to add a "room"  The rooms are stored in a mysql database

Users log in (also in mysql) and they can join any open room

The user then makes a socket connection to the room's IP and back and data travels between them very easily.

 

 

 

As stated on the prototype website:

 

Prototype is a JavaScript Framework that aims to ease development of dynamic web applications.

 

It isn't just for offline testing, it's for writing javascript code with the easy of a very good framework.

If you want help with this , i have a AJAX chatbox

http://dracopangaia.awardspace.com/shoutbox/shoutbox.php

 

Feel free to PM me for help.

 

If not just look into the source code, as you can view the JS that way.

A shoutbox isn't really a chat room, isn't it? Just from a google search, i found two scripts (i'm sure there are a lot more) which act as real chat rooms based on php with some ajax callbacks. First here, second here (scroll to the bottom).

I looked at it, didn't talk in vain. Actually a shoutbox is a shoutbox. The only thing it has in common with a chat room is the possibility of posting a message :). Real time posting, users and stuff are all missing there  ;).

 

Cheers.

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.