3

Possible Duplicate:
Using comet with PHP?

I am writing a social application with a back end written in PHP (I'm using the FuelPHP framework). I would like to notify a client that some event has occurred on the server in a similar way that Facebook does for it's notifications.

At the moment I am just using repeated polling using AJAX, but I think that I could achieve a nicer implementation using an event on the server that gets fired down to the client.

Using node.js I have achieved this sort of communication using web sockets and the socket.io module.

Is there any way I can do this sort of thing in PHP? Is PHP really that unsuited to this sort of communication? Can I somehow spawn a node based child process?

This is a lack of knowledge, could someone point me towards a solution that I can research?

This code may illustrate what I'm trying to do...

private function initEvents() {

  $events = Event::instance('chat_event_listener');

  $events->register('messageWasReceived', function($message){
    $this->handleMessageReceived($message);
  });

}

public function post_addNewMessage(){

  //Client uses Posts message to this method using AJAX

  $message = \Input::post('message');
  Event::instance('chat_event_listener')->trigger('messageWasReceived', $message);

  return $this->response(array(
    'success' => true,
    'data' => 'TO DO',
  ));

}

private function handleMessageReceived($message){
  $this->firephp->log('Message received on server: ' . $message);
  //notify client
}
Community
  • 1
  • 1
Adam Waite
  • 19,748
  • 19
  • 120
  • 146

0 Answers0