本文共 2752 字,大约阅读时间需要 9 分钟。
websocket 框架
This article we are going to learn is: How to install and run the swoft websocket server.
我们将要学习的这篇文章是:如何安装和运行swoft websocket服务器。
This article is one of a series of articles on the Swoft WebSocket Server. Let's learn about Swoft!
本文是Swoft WebSocket服务器上一系列文章之一。 让我们了解Swoft!
Swoft is a PHP high performance microservice coroutine framework. It has been published for many years and has become the best choice for php.
Swoft是一个PHP高性能微服务协程框架。 它已经发布了很多年,并已成为php的最佳选择。
It can be like Go, built-in coroutine web server and common coroutine client and is resident in memory, independent of traditional PHP-FPM.
它可以像Go,内置的协程Web服务器和通用协程客户端一样,驻留在内存中,独立于传统PHP-FPM。
There are similar Go language operations, similar to the Spring Cloud framework flexible annotations.
有类似的Go语言操作,类似于Spring Cloud框架的灵活注释。
Through three years of accumulation and direction exploration, Swoft has made Swoft the Spring Cloud in the PHP world, which is the best choice for PHP's high-performance framework and microservices management.
通过三年的积累和方向探索,Swoft使Swoft成为了PHP世界中的Spring Cloud,它是PHP高性能框架和微服务管理的最佳选择。
Use swoft-cli
tool to create new project for Websocket.
使用swoft-cli
工具为Websocket创建新项目。
php swoftcli.phar create:app --type ws swoft-ws-appcd swoft-ws-appcomposer install
Start Websocket server with php bin/swoft ws:start
command, you can see below:
用php bin/swoft ws:start
命令启动Websocket服务器,如下所示:
$ php bin/swoft ws:start Information Panel ******************************************************************************************* * WebSocket | Listen: 0.0.0.0:18308, type: TCP, mode: Process, worker: 8 *******************************************************************************************
18308
18308
Use swoft-cli
tool to create new websocket module.
使用swoft-cli
工具创建新的websocket模块。
php swoftcli.phar gen:ws-mod echo --prefix /echo
Code for echo module(app/WebSocket/EchoModule.php
) like this:
回声模块( app/WebSocket/EchoModule.php
)的代码如下:
push($fd, 'hello, welcome! :)'); }}
Here use swoft-devtool
to connect WebSocket server.
在这里使用swoft-devtool
连接WebSocket服务器。
Use php bin/swoft dclient:ws /echo
command in swoft-devtool
component to connect WebSocket server, you can see connection success message like below.
在swoft-devtool
组件中使用php bin/swoft dclient:ws /echo
命令连接WebSocket服务器,可以看到如下所示的连接成功消息。
Begin connecting to websocket server: 127.0.0.1:18308 path: /echoSuccess connect to websocket server. Now, you can send messageINTERACTIVE================================================================================server> ?Opened, welcome #1!client> hiserver> Recv: hiclient>
翻译自:
websocket 框架
转载地址:http://xzdwd.baihongyu.com/