承接 zanderwar/php-websocket 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

zanderwar/php-websocket

Composer 安装命令:

composer require zanderwar/php-websocket

包简介

A simple WebSocket Server and Client implementation in PHP.

README 文档

README

Bloatless PHP WebSockets

Simple WebSocket server and client implemented in PHP.

About

This application is an extremely simple implementation of the WebSocket Protocol in PHP. It includes a server as well as a client. This implementation is optimal to get started with WebSockets and learn something. As soon as you want to create a full featured websocket based application you might want to switch to more sophisticated solution.

Installation

Clone or download the repository to your server. The package is also installable via composer running the following command:

composer require bloatless/php-websocket

Requirements

  • PHP >= 7.2

Hint: You can use version 1.0 if you're still on PHP5.

Usage

  • Adjust cli/server.php to your requirements.
  • Run: php cli/server.php

This will start a websocket server. (By default on localhost:8000)

Server example

This will create a websocket server listening on port 8000.

There a two applications registred to the server. The demo application will be available at ws://localhost:8000/demo and the status application will be available at ws://localhost:8000/status.

// Require neccessary files here...

$server = new \Bloatless\WebSocket\Server('127.0.0.1', 8000);

// Server settings:
$server->setMaxClients(100);
$server->setCheckOrigin(false);
$server->setAllowedOrigin('foo.lh');
$server->setMaxConnectionsPerIp(100);
$server->setMaxRequestsPerMinute(2000);

// Add your applications here:
$server->registerApplication('status', \Bloatless\WebSocket\Application\StatusApplication::getInstance());
$server->registerApplication('demo', \Bloatless\WebSocket\Application\DemoApplication::getInstance());

$server->run();

Client example

This creates a WebSocket cliente, connects to a server and sends a message to the server:

$client = new \Bloatless\WebSocket\Client;
$client->connect('127.0.0.1', 8000, '/demo', 'foo.lh');
$client->sendData([
    'action' => 'echo',
    'data' => 'Hello Wolrd!'
]);

Browser example

The repository contains two demo-pages to call in your browser. You can find them in the public folder. The index.html is a simple application which you can use to send messages to the server.

The status.html will display various server information.

统计信息

  • 总下载量: 9
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 193
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-11-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固