投稿

ラベル(WebSocket)が付いた投稿を表示しています

【PHP】PHPでWebSocketサーバー - クライアント・サーバー間通信 -

イメージ
前回の記事 でPHPにより実装したWebSocketサーバーを介してのクライアント間通信を実装しました。 今回はサーバー側から一方的にクライアントへメッセージを送信してみたいと思います。 使用するライブラリは以下を使用しましたが、結果を先に言ってしまうとelephant.ioのほうはうまく行きませんでした。以下にその手順と結果を残しておきます。 wisembly/elephant.io textalk/websocket サーバーからメッセージ送信 (wisembly/elephant.io) ライブラリのインストール composer.json composer.json の require に以下を追加 "wisembly/elephant.io":"~3.0" 以下コマンドでインストール $ ./composer.phar update --lock Loading composer repositories with package information Updating dependencies (including require-dev) Package operations: 1 install, 0 updates, 0 removals - Installing wisembly/elephant.io (v3.3.1): Loading from cache Package guzzle/common is abandoned, you should avoid using it. Use guzzle/guzzle instead. Package guzzle/http is abandoned, you should avoid using it. Use guzzle/guzzle instead. Package guzzle/parser is abandoned, you should avoid using it. Use guzzle/guzzle instead. Package guzzle/stream is abandoned, you should avoid using it. Use guzzle/guzzle instead.

【PHP】PHPでWebSocketサーバー - クライアント間の通信 -

イメージ
以下の記事を参考にWebSocketをサーバーを立てて、docker+FuelPHP上で実行してみました。 http://madroom-project.blogspot.com/2013/04/phpwebsocket.html なお、FuelPHPについてフレームワークとしての機能は使用していませんので、どんなフレームワークを使っても同じ方法で行けると思います。 ライブラリのインストール composer.json の require に以下を追加 "cboden/Ratchet": "0.2.*" 以下コマンドでインストール $ ./composer.phar update --lock Loading composer repositories with package information Updating dependencies (including require-dev) Package operations: 1 install, 0 updates, 0 removals - Installing textalk/websocket (1.0.3): Loading from cache Package guzzle/common is abandoned, you should avoid using it. Use guzzle/guzzle instead. Package guzzle/http is abandoned, you should avoid using it. Use guzzle/guzzle instead. Package guzzle/parser is abandoned, you should avoid using it. Use guzzle/guzzle instead. Package guzzle/stream is abandoned, you should avoid using it. Use guzzle/guzzle instead. Writing lock file Generating autoload files 実装 WebSocketサーバー側 以下をプロジェクトの適当なディレクトリに配置します。(requ