在 Debian 上运行的 Ratchet PHP Websocket
Posted
技术标签:
【中文标题】在 Debian 上运行的 Ratchet PHP Websocket【英文标题】:Ratchet PHP Websocket running on Debian 【发布时间】:2020-11-14 13:57:30 【问题描述】:我在 Debian 上运行以下 Ratchet 脚本;
<?php
use Workerman\Worker;
require_once '/var/www/app/vendor/autoload.php';
// SSL context.
$context = array(
'ssl' => array(
'local_cert' => '/var/www/app/certs/cert.pem',
'local_pk' => '/var/www/app/certs/key.pem',
'verify_peer' => false,
)
);
// Create a Websocket server with ssl context.
$ws_worker = new Worker('websocket://my.server.ip.address:2346', $context);
// Enable SSL. WebSocket+SSL means that Secure WebSocket (wss://).
// The similar approaches for Https etc.
$ws_worker->transport = 'ssl';
$ws_worker->onMessage = function ($connection, $data)
// Send hello $data
$connection->send('Hello ' . $data);
;
Worker::runAll();
脚本运行正常
php workermanserver.php start
我明白了;
----------------------------------------------- WORKERMAN -----------------------------------------------
Workerman version:4.0.15 PHP version:7.3.23
------------------------------------------------ WORKERS ------------------------------------------------
proto user worker listen processes status
ssl root none websocket://my.server.ip:2346 1 [OK]
----------------------------------------------------------------------------------------------------
但是当我在浏览器中访问“websocket://my.server.ip.address:2346”时,我得到了;
Your search - websocket://66.175.215.122:2346 - did not match any documents.
Suggestions:
Make sure that all words are spelled correctly.
Try different keywords.
Try more general keywords.
知道我哪里出错了吗?
【问题讨论】:
【参考方案1】:websocket 在我的 android 客户端上工作。它只是在尝试直接从浏览器访问时出错。
【讨论】:
以上是关于在 Debian 上运行的 Ratchet PHP Websocket的主要内容,如果未能解决你的问题,请参考以下文章
在 PHP 上使用 Ratchet 和 WebSockets 进行私人和群聊