Skip to content

Commit 86973a5

Browse files
committed
Update readme, phpdocs, ...
1 parent 776729c commit 86973a5

10 files changed

+77
-67
lines changed

README.md

+70-28
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,81 @@
1-
PHP WebSocket
2-
=============
3-
A websocket server implemented in php.
1+
<p align="center">
2+
<img src="https://bloatless.org/img/logo.svg" width="60px" height="80px">
3+
</p>
44

5-
- Supports websocket draft hybi-10,13 (Currently tested with Chrome 18 and Firefox 11).
6-
- Supports origin-check.
7-
- Supports various security/performance settings.
8-
- Supports binary frames. (Currently receive only)
9-
- Supports wss. (Needs valid certificate in Firefox.)
10-
- Application module, the server can be extended by custom behaviors.
5+
<h1 align="center">Bloatless PHP WebSockets</h1>
116

12-
## Bugs/Todos/Hints
13-
- Add support for fragmented frames.
7+
<p align="center">
8+
Simple WebSocket server and client implemented in PHP.
9+
</p>
1410

15-
## Server example
11+
## About
1612

17-
This creates a server on localhost:8000 with one Application that listens on `ws://localhost:8000/demo`:
13+
This application is an extremely simple implementation of the [WebSocket Protocol](https://tools.ietf.org/html/rfc6455)
14+
in PHP. It includes a server as well as a client. This implementation is optimal to get started with WebSockets and
15+
learn something. As soon as you want to create a full featured websocket based application you might want to switch
16+
to more sophisticated solution.
1817

19-
$server = new \WebSocket\Server('127.0.0.1', 8000, false); // host,port,ssl
18+
## Installation
2019

21-
// server settings:
22-
$server->setCheckOrigin(true);
23-
$server->setAllowedOrigin('foo.lh');
24-
$server->setMaxClients(100);
25-
$server->setMaxConnectionsPerIp(20);
26-
$server->setMaxRequestsPerMinute(1000);
20+
Clone or download the repository to your server.
2721

28-
$server->registerApplication('demo', \WebSocket\Application\DemoApplication::getInstance());
29-
$server->run();
22+
### Requirements
3023

31-
## Libraries used
24+
* PHP >= 7.2
3225

33-
- [SplClassLoader](http://gist.github.com/221634) by the PHP Standards Working Group
34-
- [jQuery](http://jquery.com/)
35-
- [CoffeeScript PHP] (https://github.com/alxlit/coffeescript-php)
26+
Hint: You can use version 1.0 if you're still on PHP5.
3627

37-
## Demo
3828

39-
- Check out http://jitt.li for a sample-project using this websocket server.
29+
## Usage
30+
31+
* Adjust `cli/server.php` to your requirements.
32+
* Run: `php cli/server.php`
33+
34+
This will start a websocket server. (By default on localhost:8000)
35+
36+
### Server example
37+
38+
This will create a websocket server listening on port 8000.
39+
40+
There a two applications registred to the server. The demo application will be available at `ws://localhost:8000/demo`
41+
and the status application will be available at `ws://localhost:8000/status`.
42+
43+
```php
44+
// Require neccessary files here...
45+
46+
$server = new \Bloatless\WebSocket\Server('127.0.0.1', 8000);
47+
48+
// Server settings:
49+
$server->setMaxClients(100);
50+
$server->setCheckOrigin(false);
51+
$server->setAllowedOrigin('foo.lh');
52+
$server->setMaxConnectionsPerIp(100);
53+
$server->setMaxRequestsPerMinute(2000);
54+
55+
// Add your applications here:
56+
$server->registerApplication('status', \Bloatless\WebSocket\Application\StatusApplication::getInstance());
57+
$server->registerApplication('demo', \Bloatless\WebSocket\Application\DemoApplication::getInstance());
58+
59+
$server->run();
60+
61+
```
62+
63+
### Client example
64+
65+
This creates a WebSocket cliente, connects to a server and sends a message to the server:
66+
67+
```php
68+
$client = new \Bloatless\WebSocket\Client;
69+
$client->connect('127.0.0.1', 8000, '/demo', 'foo.lh');
70+
$client->sendData([
71+
'action' => 'echo',
72+
'data' => 'Hello Wolrd!'
73+
]);
74+
```
75+
76+
### Browser example
77+
78+
The repository contains two demo-pages to call in your browser. You can find them in the `public` folder.
79+
The `index.html` is a simple application which you can use to send messages to the server.
80+
81+
The `status.html` will display various server information.

cli/client_demo.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
ini_set('display_errors', 1);
33
error_reporting(E_ALL);
44

5-
require_once __DIR__ . '/../src/Client.php';
5+
require __DIR__ . '/../src/Client.php';
66

77
$clients = [];
88
$testClients = 30;

cli/server.php

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
<?php
22

3-
ini_set('display_errors', 1);
4-
error_reporting(E_ALL);
5-
63
require __DIR__ . '/../src/Connection.php';
74
require __DIR__ . '/../src/Socket.php';
85
require __DIR__ . '/../src/Server.php';

src/Application/Application.php

-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@
44

55
namespace Bloatless\WebSocket\Application;
66

7-
/**
8-
* WebSocket Server Application
9-
*
10-
* @author Nico Kaiser <nico@kaiser.me>
11-
*/
127
abstract class Application implements ApplicationInterface
138
{
149
/**

src/Application/DemoApplication.php

-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66

77
use Bloatless\WebSocket\Connection;
88

9-
/**
10-
* Websocket-Server demo and test application.
11-
*
12-
* @author Simon Samtleben <web@lemmingzshadow.net>
13-
*/
149
class DemoApplication extends Application
1510
{
1611
/**

src/Application/StatusApplication.php

-6
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66

77
use Bloatless\WebSocket\Connection;
88

9-
/**
10-
* Shiny WSS Status Application
11-
* Provides live server infos/messages to client/browser.
12-
*
13-
* @author Simon Samtleben <web@lemmingzshadow.net>
14-
*/
159
class StatusApplication extends Application
1610
{
1711
/**

src/Client.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
namespace Bloatless\WebSocket;
66

77
/**
8-
* Very basic websocket client.
9-
* Supporting draft hybi-10.
8+
* Simple WebSocket client.
109
*
11-
* @author Simon Samtleben <web@lemmingzshadow.net>
12-
* @version 2011-10-18
10+
* @author Simon Samtleben <foo@bloatless.org>
11+
* @version 2.0
1312
*/
1413
class Client
1514
{

src/Connection.php

-6
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66

77
use Bloatless\WebSocket\Application\ApplicationInterface;
88

9-
/**
10-
* WebSocket Connection class
11-
*
12-
* @author Nico Kaiser <nico@kaiser.me>
13-
* @author Simon Samtleben <web@lemmingzshadow.net>
14-
*/
159
class Connection
1610
{
1711
public $waitingForData = false;

src/Server.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
use Bloatless\WebSocket\Application\ApplicationInterface;
88

99
/**
10-
* Shiny WSS
10+
* Simple WebSocket server implementation in PHP.
1111
*
12+
* @author Simon Samtleben <foo@bloatless.org>
1213
* @author Nico Kaiser <nico@kaiser.me>
13-
* @author Simon Samtleben <web@lemmingzshadow.net>
14+
* @version 2.0
1415
*/
1516
class Server extends Socket
1617
{

src/Socket.php

-7
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@
44

55
namespace Bloatless\WebSocket;
66

7-
/**
8-
* Socket class
9-
*
10-
* @author Moritz Wutz <moritzwutz@gmail.com>
11-
* @author Nico Kaiser <nico@kaiser.me>
12-
* @version 0.2
13-
*/
147
class Socket
158
{
169
/**

0 commit comments

Comments
 (0)