javascriptjqueryajaxcomet

how does comet work with php?


when i use comet iframe i just send script tags from backend php file to front end and javascript is displaying it.

can someone explain briefly where a comet server comes up in the picture and how the communication will be between frontend (javascript), backend (php) and the comet server.

cause i read that if you are going to let a lot of users use your comet application it's better to have a comet server. but i dont quite understand the coupling between these parts.


Solution

  • use this link:

    http://www.zeitoun.net/articles/comet_and_php/start

    That is the best tutorial i could found, and takes 1 min to try;

    in short:

    alt text

    ( image from that tutorial )

    index, can be html or php, creates a request, which php doesnt answer until there is data to send back, with chat, when someone sends you a message.

    If you have many users chatting, i recommend using a java chat app

    otherwise your server will load up with running php engines ( each unanswered request keeps a php engine alive, which is server capacity ).

    http://streamhub.blogspot.com/2009/07/tutorial-building-comet-chat.html

    this should help you out with that, but you do need java hosting :)

    have fun

    edit:

    just read the other server part; sending requests to your own server can get messed because the timeout function may not work well, so the server crashes, an independant server timeouts the connection after a certain amount of time, no matter what.