Please can any body help me with a simple script on how to write an ajax longing in php.

I doing some on chat and have been using the old polling. so I want to switch to long pooling. so the browser would only display messages when there is a new message in the database

Thanks for taking out time to read my post.

Recommended Answers

All 3 Replies

Member Avatar

An old project called APE (comet) has been kicking around for a while. You need to set up your own server for this as I don't think Apache can do it. The solutions I've seen for php tend to be 'repeated polling' as opposed to long polling - not really comet in other words (e.g. - which may overwhelm the server. Using some flavour of timeout for sleep() periods should force the end of the poll though, otherwise you could have major processing even though the user has gone away.

Sidenote, assuming you build this from scratch: suppose you implement long polling for an AJAX call to PHP. This would just move the problem to the PHP script, as it would need to implement the same original polling mechanism to get info from the database.

Perhaps moving to Javascript for this would be the better solution, using node.js (if possible).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.