Overview
The PHP-only library allows you to run Ajax IM on a shared server, where you don’t usually have the ability to run other servers or applications. Despite being pure PHP, it allows for all three types of AJAX: short polling, long polling, and streaming; the latter two are considered forms of Comet. The script requires that a database library (such as the included MySQL library) be in use in order to handle authentication and sending/receiving messages.
This library is database-agnostic, meaning that it should work with any properly-constructed database library.
If at all possible, it is recommended that you use the Node.js server. This PHP-only class is only included for compatibility and convenience.
poll($method) Function
The poll($method) function is where all the “action” happens after authentication. The method of polling used by Ajax IM is defined when you initialize your AjaxIM object on the client side. This function is called automatically by the server script, server.php. As previously mentioned, you have three options for polling method:
shortpolling — The server checks for any messages, and returns immediately, whether or not it has found any data.longpolling — The server checks for messages, and continues checking every few seconds for up to 30 seconds or until data is found (whichever comes first). Upon finding data, it is sent and the connection is closed (and the process repeats). Note: The 30 second timeout has been implemented to try and reduce server strain.comet(streaming) — The server checks for messages and keeps the connection open indefinitely. As new data arrives, it is pushed to the client via<script>tags.
Leave a comment