An open API service indexing awesome lists of open source software.

https://github.com/cseufert/php-socket

A PHP Comet Library with Fallbacks
https://github.com/cseufert/php-socket

Last synced: 21 days ago
JSON representation

A PHP Comet Library with Fallbacks

Awesome Lists containing this project

README

        

php-socket
==========

A PHP Comet Library

An example of how to use (server):

daemon.php
```php
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
getClient(123); // Client ID is 123 here
$client->raise('message', ['message'=>$message]);
```

comet.php
```php
process();
```

And an example of the JavaScript code:

```javascript
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});
```