homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

PHP based Chatroom
Where to find a good tutorial

5+ Year Member

Msg#: 3662346 posted 10:09 pm on May 29, 2008 (gmt 0)


I used to see some chats on some websites and I am wondering if this can be done with PHP.

Can someone point me to a good online tutorial?

Thanks in advance



5+ Year Member

Msg#: 3662346 posted 10:23 pm on May 29, 2008 (gmt 0)

As in forum? Don't reinvent the wheel:



5+ Year Member

Msg#: 3662346 posted 10:34 pm on May 29, 2008 (gmt 0)

I meant a tutorial where I can learn to write the php program running a chat, with all the info of number of people chatting ,etc...


5+ Year Member

Msg#: 3662346 posted 6:52 pm on May 30, 2008 (gmt 0)

I've developed something like this in the past, and it worked pretty well. It was a CodeIgniter library, actually.

I can tell you that you'll need to know how to use AJAX, and have a library that handles AJAX calls efficiently and quickly. The YUI library does wonders in helping the client-side development, and its documentation is excellent. I would recommend using JSON encoding instead of XML no matter what solution you pick, as in a chat system you will need to have a request/response several times per minute for every user, and XML as a transmission mechanism is amazingly inefficient compared to JSON, especially for empty requests (I.E. no new messages have been sent since the last request).

The tricky part in building this sort of a system is that only the client can initiate communication with the server. In a normal instant-messaging scenario, the server initiates communication with the client, telling the client that a new message is available, then transmitting it.

You'll have to use a timed event (setInterval in Javascript works wonderfully for this) on the client to repeatedly ping the server to request recent messages. This "ping" should probably include the time at which the last ping occurred (or at least a cookie that allows you to store this information in the session), so it can retrieve messages occurring since then from the database.

Your server-side code will have to be lean and efficient--you won't have the luxury of spending even a half second processing the request if you want to have the chat interface seem responsive. Also keep in mind that the sheer volume of requests coming in at the same time can potentially be crippling with a large processing time if there are even 50 users online at any given time.

To my knowledge there are no tutorials available for building this sort of thing--they'd have to be long and involved, really, in order to have a prayer at being successful.

You'll need a solid knowledge of the following technologies to complete a web chat system:
CSS (inline HTML styling will use up so much bandwidth in transfers that your system -will- grind to a halt)
YUI (or other AJAX-capable library)

PHP has a wonderful json_encode() function that can encode any variable type into JSON, but it only comes bundled and enabled by default with PHP 5.2 or newer. Between this function and the YUI library (which includes a JSON decode function) your transmissions will be all but handled for you.


WebmasterWorld Administrator coopster us a WebmasterWorld Top Contributor of All Time 10+ Year Member

Msg#: 3662346 posted 11:56 am on Jun 1, 2008 (gmt 0)

Can someone point me to a good online tutorial?

Zend put out a Ajax Chat Tutorial [devzone.zend.com] awhile ago that may help you get started.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved