- HTTP Server
- Websocket Server
- TCP Client/Server
- Async Redis/HTTP/Websocket Client
Last active
September 1, 2019 18:42
-
-
Save javascripto/66247748fde4aa89d03ff262f2331071 to your computer and use it in GitHub Desktop.
php swoole extension Instalation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Instalation | |
| sudo apt install -y php-pear php-dev | |
| sudo pecl channel-update pecl.php.net | |
| sudo pecl install swoole | |
| # Enable swoole extension in php.ini | |
| # php -i | grep php.ini$ # php.ini path | |
| php_ini_path=$(ini=$(php -i | grep php.ini$) && echo ${ini:29}) | |
| echo "extension=swoole.so" >> $php_ini_path |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const ws = new WebSocket('ws://localhost:9502'); | |
| ws.onmessage = r => console.log(r.data); | |
| ws.send('Hello from Browser!'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $server = new swoole_websocket_server("127.0.0.1", 9502); | |
| $server->on('open', function($server, $req) { | |
| echo "connection open: {$req->fd}\n"; | |
| }); | |
| $server->on('message', function($server, $frame) { | |
| echo "received message: {$frame->data}\n"; | |
| $server->push($frame->fd, json_encode(["hello", "world", "from", "server"])); | |
| }); | |
| $server->on('close', function($server, $fd) { | |
| echo "connection close: {$fd}\n"; | |
| }); | |
| $server->start(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment