A McGraw Hill Book Plug-in PHP: 100 Power Solutions
By Robin Nixon (McGraw Hill 2010, ISBN 978-0071666596)

Home | About | Buy It | Download | Contact

Select Chapter: 1  2  3  4  5  6  7  8  9 10 11 12

Chapter 8: Plug-in 54 - Post to Chat

Some of the more popular features of a website are messaging and chat facilities, particularly if they are fast and easy to use, which this plug-in is - even though it's only about 30 lines of actual code, and not a sign of Java or Flash in sight. I first wrote the predecessor of this chat in 1996 using Perl scripts and later transported it to compiled C code and then, with the advent of PHP, due to it's tremendous speed (even though it's not compiled) I rewrote it again. But the code's format has remained pretty much the same; a simple text file which is continuously read from and written to, using file locking to prevent file corruption. It also uses a feature that predates Ajax (the sending of background requests to a server to exchange data) but provides similar functionality, in that messages appear in the browser when posted, without having to refresh the page.

The Figure shows this Post part of the chat engine being used to post a message, with and without flood control.