Chappers Posted August 22, 2008 Share Posted August 22, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/120922-viability-of-realtime-chat-room-coded-in-php-only/ Share on other sites More sharing options...
Prismatic Posted August 22, 2008 Share Posted August 22, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/120922-viability-of-realtime-chat-room-coded-in-php-only/#findComment-623333 Share on other sites More sharing options...
Fadion Posted August 22, 2008 Share Posted August 22, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/120922-viability-of-realtime-chat-room-coded-in-php-only/#findComment-623335 Share on other sites More sharing options...
Chappers Posted August 22, 2008 Author Share Posted August 22, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/120922-viability-of-realtime-chat-room-coded-in-php-only/#findComment-623352 Share on other sites More sharing options...
cooldude832 Posted August 22, 2008 Share Posted August 22, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/120922-viability-of-realtime-chat-room-coded-in-php-only/#findComment-623357 Share on other sites More sharing options...
Fadion Posted August 22, 2008 Share Posted August 22, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/120922-viability-of-realtime-chat-room-coded-in-php-only/#findComment-623359 Share on other sites More sharing options...
DeanWhitehouse Posted August 23, 2008 Share Posted August 23, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/120922-viability-of-realtime-chat-room-coded-in-php-only/#findComment-623464 Share on other sites More sharing options...
Fadion Posted August 23, 2008 Share Posted August 23, 2008 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). Quote Link to comment https://forums.phpfreaks.com/topic/120922-viability-of-realtime-chat-room-coded-in-php-only/#findComment-623493 Share on other sites More sharing options...
DeanWhitehouse Posted August 23, 2008 Share Posted August 23, 2008 Please view it first, and it was the principal ,as it can act as a chat room. Quote Link to comment https://forums.phpfreaks.com/topic/120922-viability-of-realtime-chat-room-coded-in-php-only/#findComment-623496 Share on other sites More sharing options...
Fadion Posted August 23, 2008 Share Posted August 23, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/120922-viability-of-realtime-chat-room-coded-in-php-only/#findComment-623506 Share on other sites More sharing options...
DeanWhitehouse Posted August 23, 2008 Share Posted August 23, 2008 It is realtime, and as i said it is just the principal to help get him started. Quote Link to comment https://forums.phpfreaks.com/topic/120922-viability-of-realtime-chat-room-coded-in-php-only/#findComment-623520 Share on other sites More sharing options...
Fadion Posted August 23, 2008 Share Posted August 23, 2008 Ok mate ok. Let's leave it like this. I'm not up for a discussion on such a pointless subject. Cheers. Quote Link to comment https://forums.phpfreaks.com/topic/120922-viability-of-realtime-chat-room-coded-in-php-only/#findComment-623529 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.