Skip to content

cseufert/php-socket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 

Repository files navigation

php-socket

A PHP Comet Library

An example of how to use (server):

daemon.php

<?php
$comet = new comet();
$comet->on('connection', function($client) {
  $client->raise('ping');
  $client->on('pong', function($data) {
    if($data['clientid'] == $client->id) {
      // Connection OK!
  });
});

You can also send messages to clients outside an active comet session:

<?php
$message = "You have mail";
$comet = new comet();
$client = $comet->getClient(123); // Client ID is 123 here
$client->raise('message', ['message'=>$message]);

comet.php

<?php
$session = new cometSession();
$session->process();

And an example of the JavaScript code:

comet.on('ping', function(data) {
  comet.raise('pong', {'clientid': comet.client.id});
});
comet.on('message', function(data) {
  console.log("Message received: " + data['message']);
});
comet.start({'server': '/comet.php', 'clientid': 123});

About

A PHP Comet Library with Fallbacks

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published