Download the PHP package imiphp/project-websocket without Composer

On this page you can find all versions of the php package imiphp/project-websocket. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package project-websocket

说明

这是一个 imi WebSocket 项目开发骨架项目,你可以基于这个项目来开发你的项目。

imi 框架:https://www.imiphp.com

imi 文档:https://doc.imiphp.com


这是一个 WebSocket、Http 共存服务的示例

WebSocket 连接地址:ws://127.0.0.1:8081/ws

Swoole 支持 WebSocket+Http 共享端口,Http 测试访问地址:http://127.0.0.1:8081/http://127.0.0.1:8081/api

Workerman Http 测试访问地址:http://127.0.0.1:8080/http://127.0.0.1:8080/api

test-html/index.html 文件可以连接 WebSocket 进行调试

安装

创建项目:composer create-project imiphp/project-websocket:~2.1.0

如果你希望在 Swoole 运行 imi:composer require imiphp/imi-swoole:~2.1.0

配置

项目命名空间

默认是 ImiApp,可以在 composer.json 中修改:

然后替换代码中的命名空间即可。

运行配置

项目配置目录:config

WebSocket 服务器配置目录:WebSocketServer/config

启动命令

普通启动:

Swoole:vendor/bin/imi-swoole swoole/start

Workerman:vendor/bin/imi-workerman workerman/start

网关环境启动:

配置文件一键切换网关模式:mv config/config.php config/config.php.bak && mv config/config-geteaway.php config/config.php && mv WebSocketServer/config/config.php WebSocketServer/config/config.php.bak && mv WebSocketServer/config/config-geteaway.php WebSocketServer/config/config.php

注册中心:vendor/bin/imi-workerman workerman/start --name register

网关:vendor/bin/imi-workerman workerman/start --name gateway

Swoole Worker:vendor/bin/imi-swoole swoole/start

Workerman Worker:vendor/bin/imi-workerman workerman/start --name websocketWorker

指定 worker 名称:(多个 worker 实例需要不一样的名字)

切换环境运行前建议删除 .runtime/imi-runtime 目录:rm -rf .runtime/imi-runtime

Swoole 网关模式需要依赖 Workerman 启动 register、gateway,其它服务器配置先注释;运行时需要先 workerman 启动命令,再运行 swoole 启动命令

测试

连接:ws://127.0.0.1:8081/ws

发送:

返回:

权限

.runtime 目录需要有可写权限

多种模式

本地

支持 Swoole,适合单实例部署

支持 Workerman,适合单进程开发调试

config/config.php:

WebSocketServer/config/config.php:

Redis 分布式

支持 Swoole,适合分布式

config/config.php:

pools.redis.resource.options 下的 \Redis::OPT_READ_TIMEOUT 注释去除。

WebSocketServer/config/config.php:

Channel 模式

支持 Workerman,适合所有场景

config/config.php:

WebSocketServer/config/config.php:

Workerman Gateway 模式

支持 Swoole、Workerman,适合分布式场景

config/config.php:

WebSocketServer/config/config.php:

生产环境

关闭热更新:config/beans.phphotUpdate.status 设为 false

生产环境建议只保留一个容器,可以提升性能,imi 官方推荐使用 Swoole

移除 imi-workermancomposer remove imiphp/imi-workerman

移除 imi-swoolecomposer remove imiphp/imi-swoole(不推荐)

代码质量

格式化代码

内置 php-cs-fixer,统一代码风格。

配置文件 .php-cs-fixer.php,可根据自己实际需要进行配置,文档:https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/doc/config.rst

格式化项目: ./vendor/bin/php-cs-fixer fix

格式化指定文件: ./vendor/bin/php-cs-fixer fix test.php

代码静态分析

内置 phpstan,可规范代码,排查出一些隐藏问题。

配置文件 phpstan.neon,可根据自己实际需要进行配置,文档:https://phpstan.org/config-reference

分析项目: ./vendor/bin/phpstan

分析指定文件: ./vendor/bin/phpstan test.php

测试用例

内置 phpunit,可以实现自动化测试。

文档:https://phpunit.readthedocs.io/en/9.5/

测试用例 demo:tests/Module/Test/TestServiceTest.php

运行测试用例:composer test


All versions of project-websocket with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
imiphp/imi Version 2.1.x-dev
imiphp/imi-workerman Version 2.1.x-dev
imiphp/imi-workerman-gateway Version 2.1.x-dev
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package imiphp/project-websocket contains the following files

Loading the files please wait ....