Commit 5372a577 authored by 刘小敏's avatar 刘小敏

添加wokerman包

parent a277a9d5
...@@ -15,7 +15,7 @@ return [ ...@@ -15,7 +15,7 @@ return [
'inside_host' => '127.0.0.1', 'inside_host' => '127.0.0.1',
'inside_port' => '9292', 'inside_port' => '9292',
'port' => '2222', 'port' => '2222',
'ssl' => 'reverse_proxy', 'ssl' => 'none',
'ssl_cert' => '', 'ssl_cert' => '',
'ssl_key' => '', 'ssl_key' => '',
], ],
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
return [ return [
'host' => '127.0.0.1', 'host' => '127.0.0.1',
'password' => '',
'port' => '6379', 'port' => '6379',
'select' => '1', 'select' => '1',
'timeout' => '0', 'timeout' => '0',
'persistent' => false, 'persistent' => false,
'password' => '',
]; ];
\ No newline at end of file
<?php <?php
return array ( return array (
'name' => '我的网站', 'name' => '爱岛珠宝',
'beian' => '', 'beian' => '',
'cdnurl' => '', 'cdnurl' => '',
'version' => '1.0.3', 'version' => '1.0.0',
'timezone' => 'Asia/Shanghai', 'timezone' => 'Asia/Shanghai',
'forbiddenip' => '', 'forbiddenip' => '',
'languages' => 'languages' =>
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
"ext-curl": "*", "ext-curl": "*",
"ext-pdo": "*", "ext-pdo": "*",
"ext-bcmath": "*", "ext-bcmath": "*",
"workerman/phpsocket.io": "^2.2" "workerman/phpsocket.io": "^2.3"
}, },
"config": { "config": {
"preferred-install": "dist", "preferred-install": "dist",
......
...@@ -32,7 +32,7 @@ private static $installed = array ( ...@@ -32,7 +32,7 @@ private static $installed = array (
'aliases' => 'aliases' =>
array ( array (
), ),
'reference' => 'd3c0b97323772b72bcb7167be81d17ea5ea513cc', 'reference' => 'a277a9d5c790c427d34713208f810f9fcb44c8b9',
'name' => 'fastadminnet/fastadmin', 'name' => 'fastadminnet/fastadmin',
), ),
'versions' => 'versions' =>
...@@ -71,7 +71,7 @@ private static $installed = array ( ...@@ -71,7 +71,7 @@ private static $installed = array (
'aliases' => 'aliases' =>
array ( array (
), ),
'reference' => 'd3c0b97323772b72bcb7167be81d17ea5ea513cc', 'reference' => 'a277a9d5c790c427d34713208f810f9fcb44c8b9',
), ),
'fastadminnet/fastadmin-addons' => 'fastadminnet/fastadmin-addons' =>
array ( array (
...@@ -426,8 +426,8 @@ private static $installed = array ( ...@@ -426,8 +426,8 @@ private static $installed = array (
), ),
'symfony/polyfill-mbstring' => 'symfony/polyfill-mbstring' =>
array ( array (
'pretty_version' => 'v1.36.0', 'pretty_version' => 'v1.37.0',
'version' => '1.36.0.0', 'version' => '1.37.0.0',
'aliases' => 'aliases' =>
array ( array (
), ),
...@@ -435,8 +435,8 @@ private static $installed = array ( ...@@ -435,8 +435,8 @@ private static $installed = array (
), ),
'symfony/polyfill-php73' => 'symfony/polyfill-php73' =>
array ( array (
'pretty_version' => 'v1.36.0', 'pretty_version' => 'v1.37.0',
'version' => '1.36.0.0', 'version' => '1.37.0.0',
'aliases' => 'aliases' =>
array ( array (
), ),
...@@ -444,8 +444,8 @@ private static $installed = array ( ...@@ -444,8 +444,8 @@ private static $installed = array (
), ),
'symfony/polyfill-php80' => 'symfony/polyfill-php80' =>
array ( array (
'pretty_version' => 'v1.36.0', 'pretty_version' => 'v1.37.0',
'version' => '1.36.0.0', 'version' => '1.37.0.0',
'aliases' => 'aliases' =>
array ( array (
), ),
...@@ -535,12 +535,12 @@ private static $installed = array ( ...@@ -535,12 +535,12 @@ private static $installed = array (
), ),
'workerman/phpsocket.io' => 'workerman/phpsocket.io' =>
array ( array (
'pretty_version' => 'v2.2.2', 'pretty_version' => 'v2.3.0',
'version' => '2.2.2.0', 'version' => '2.3.0.0',
'aliases' => 'aliases' =>
array ( array (
), ),
'reference' => '5f96eace9f2bcec82555a97ac9867b732024d3b6', 'reference' => 'eb702ce447aafb42d3390f69cdf4f9acfae673c8',
), ),
'workerman/workerman' => 'workerman/workerman' =>
array ( array (
......
...@@ -12,11 +12,11 @@ return array( ...@@ -12,11 +12,11 @@ return array(
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => $vendorDir . '/symfony/polyfill-mbstring/bootstrap.php', '0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => $vendorDir . '/symfony/polyfill-mbstring/bootstrap.php',
'0d59ee240a4cd96ddbb4ff164fccea4d' => $vendorDir . '/symfony/polyfill-php73/bootstrap.php', '0d59ee240a4cd96ddbb4ff164fccea4d' => $vendorDir . '/symfony/polyfill-php73/bootstrap.php',
'37a3dc5111fe8f707ab4c132ef1dbc62' => $vendorDir . '/guzzlehttp/guzzle/src/functions_include.php', '37a3dc5111fe8f707ab4c132ef1dbc62' => $vendorDir . '/guzzlehttp/guzzle/src/functions_include.php',
'9b552a3cc426e3287cc811caefa3cf53' => $vendorDir . '/topthink/think-helper/src/helper.php',
'2cffec82183ee1cea088009cef9a6fc3' => $vendorDir . '/ezyang/htmlpurifier/library/HTMLPurifier.composer.php', '2cffec82183ee1cea088009cef9a6fc3' => $vendorDir . '/ezyang/htmlpurifier/library/HTMLPurifier.composer.php',
'9b552a3cc426e3287cc811caefa3cf53' => $vendorDir . '/topthink/think-helper/src/helper.php',
'f7e3d8cd19cf23ce3883a6a51d791b77' => $vendorDir . '/fastadminnet/fastadmin-addons/src/common.php',
'f0e7e63bbb278a92db02393536748c5f' => $vendorDir . '/overtrue/wechat/src/Kernel/Support/Helpers.php', 'f0e7e63bbb278a92db02393536748c5f' => $vendorDir . '/overtrue/wechat/src/Kernel/Support/Helpers.php',
'6747f579ad6817f318cc3a7e7a0abb93' => $vendorDir . '/overtrue/wechat/src/Kernel/Helpers.php', '6747f579ad6817f318cc3a7e7a0abb93' => $vendorDir . '/overtrue/wechat/src/Kernel/Helpers.php',
'1cfd2761b63b0a29ed23657ea394cb2d' => $vendorDir . '/topthink/think-captcha/src/helper.php', '1cfd2761b63b0a29ed23657ea394cb2d' => $vendorDir . '/topthink/think-captcha/src/helper.php',
'cc56288302d9df745d97c934d6a6e5f0' => $vendorDir . '/topthink/think-queue/src/common.php', 'cc56288302d9df745d97c934d6a6e5f0' => $vendorDir . '/topthink/think-queue/src/common.php',
'f7e3d8cd19cf23ce3883a6a51d791b77' => $vendorDir . '/fastadminnet/fastadmin-addons/src/common.php',
); );
...@@ -9,7 +9,7 @@ return array( ...@@ -9,7 +9,7 @@ return array(
'think\\helper\\' => array($vendorDir . '/topthink/think-helper/src'), 'think\\helper\\' => array($vendorDir . '/topthink/think-helper/src'),
'think\\composer\\' => array($vendorDir . '/topthink/think-installer/src'), 'think\\composer\\' => array($vendorDir . '/topthink/think-installer/src'),
'think\\captcha\\' => array($vendorDir . '/topthink/think-captcha/src'), 'think\\captcha\\' => array($vendorDir . '/topthink/think-captcha/src'),
'think\\' => array($baseDir . '/thinkphp/library/think', $vendorDir . '/topthink/think-queue/src', $vendorDir . '/fastadminnet/fastadmin-addons/src'), 'think\\' => array($vendorDir . '/fastadminnet/fastadmin-addons/src', $baseDir . '/thinkphp/library/think', $vendorDir . '/topthink/think-queue/src'),
'addons\\' => array($baseDir . '/addons'), 'addons\\' => array($baseDir . '/addons'),
'ZipStream\\' => array($vendorDir . '/maennchen/zipstream-php/src'), 'ZipStream\\' => array($vendorDir . '/maennchen/zipstream-php/src'),
'Workerman\\' => array($vendorDir . '/workerman/workerman'), 'Workerman\\' => array($vendorDir . '/workerman/workerman'),
......
...@@ -13,13 +13,13 @@ class ComposerStaticInitf3106b6ef3260b6914241eab0bed11c1 ...@@ -13,13 +13,13 @@ class ComposerStaticInitf3106b6ef3260b6914241eab0bed11c1
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php', '0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
'0d59ee240a4cd96ddbb4ff164fccea4d' => __DIR__ . '/..' . '/symfony/polyfill-php73/bootstrap.php', '0d59ee240a4cd96ddbb4ff164fccea4d' => __DIR__ . '/..' . '/symfony/polyfill-php73/bootstrap.php',
'37a3dc5111fe8f707ab4c132ef1dbc62' => __DIR__ . '/..' . '/guzzlehttp/guzzle/src/functions_include.php', '37a3dc5111fe8f707ab4c132ef1dbc62' => __DIR__ . '/..' . '/guzzlehttp/guzzle/src/functions_include.php',
'9b552a3cc426e3287cc811caefa3cf53' => __DIR__ . '/..' . '/topthink/think-helper/src/helper.php',
'2cffec82183ee1cea088009cef9a6fc3' => __DIR__ . '/..' . '/ezyang/htmlpurifier/library/HTMLPurifier.composer.php', '2cffec82183ee1cea088009cef9a6fc3' => __DIR__ . '/..' . '/ezyang/htmlpurifier/library/HTMLPurifier.composer.php',
'9b552a3cc426e3287cc811caefa3cf53' => __DIR__ . '/..' . '/topthink/think-helper/src/helper.php',
'f7e3d8cd19cf23ce3883a6a51d791b77' => __DIR__ . '/..' . '/fastadminnet/fastadmin-addons/src/common.php',
'f0e7e63bbb278a92db02393536748c5f' => __DIR__ . '/..' . '/overtrue/wechat/src/Kernel/Support/Helpers.php', 'f0e7e63bbb278a92db02393536748c5f' => __DIR__ . '/..' . '/overtrue/wechat/src/Kernel/Support/Helpers.php',
'6747f579ad6817f318cc3a7e7a0abb93' => __DIR__ . '/..' . '/overtrue/wechat/src/Kernel/Helpers.php', '6747f579ad6817f318cc3a7e7a0abb93' => __DIR__ . '/..' . '/overtrue/wechat/src/Kernel/Helpers.php',
'1cfd2761b63b0a29ed23657ea394cb2d' => __DIR__ . '/..' . '/topthink/think-captcha/src/helper.php', '1cfd2761b63b0a29ed23657ea394cb2d' => __DIR__ . '/..' . '/topthink/think-captcha/src/helper.php',
'cc56288302d9df745d97c934d6a6e5f0' => __DIR__ . '/..' . '/topthink/think-queue/src/common.php', 'cc56288302d9df745d97c934d6a6e5f0' => __DIR__ . '/..' . '/topthink/think-queue/src/common.php',
'f7e3d8cd19cf23ce3883a6a51d791b77' => __DIR__ . '/..' . '/fastadminnet/fastadmin-addons/src/common.php',
); );
public static $prefixLengthsPsr4 = array ( public static $prefixLengthsPsr4 = array (
...@@ -119,9 +119,9 @@ class ComposerStaticInitf3106b6ef3260b6914241eab0bed11c1 ...@@ -119,9 +119,9 @@ class ComposerStaticInitf3106b6ef3260b6914241eab0bed11c1
), ),
'think\\' => 'think\\' =>
array ( array (
0 => __DIR__ . '/../..' . '/thinkphp/library/think', 0 => __DIR__ . '/..' . '/fastadminnet/fastadmin-addons/src',
1 => __DIR__ . '/..' . '/topthink/think-queue/src', 1 => __DIR__ . '/../..' . '/thinkphp/library/think',
2 => __DIR__ . '/..' . '/fastadminnet/fastadmin-addons/src', 2 => __DIR__ . '/..' . '/topthink/think-queue/src',
), ),
'addons\\' => 'addons\\' =>
array ( array (
......
...@@ -2509,8 +2509,8 @@ ...@@ -2509,8 +2509,8 @@
}, },
{ {
"name": "symfony/polyfill-mbstring", "name": "symfony/polyfill-mbstring",
"version": "v1.36.0", "version": "v1.37.0",
"version_normalized": "1.36.0.0", "version_normalized": "1.37.0.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-mbstring.git", "url": "https://github.com/symfony/polyfill-mbstring.git",
...@@ -2573,7 +2573,7 @@ ...@@ -2573,7 +2573,7 @@
"shim" "shim"
], ],
"support": { "support": {
"source": "https://github.com/symfony/polyfill-mbstring/tree/v1.36.0" "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.37.0"
}, },
"funding": [ "funding": [
{ {
...@@ -2597,8 +2597,8 @@ ...@@ -2597,8 +2597,8 @@
}, },
{ {
"name": "symfony/polyfill-php73", "name": "symfony/polyfill-php73",
"version": "v1.36.0", "version": "v1.37.0",
"version_normalized": "1.36.0.0", "version_normalized": "1.37.0.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-php73.git", "url": "https://github.com/symfony/polyfill-php73.git",
...@@ -2656,7 +2656,7 @@ ...@@ -2656,7 +2656,7 @@
"shim" "shim"
], ],
"support": { "support": {
"source": "https://github.com/symfony/polyfill-php73/tree/v1.36.0" "source": "https://github.com/symfony/polyfill-php73/tree/v1.37.0"
}, },
"funding": [ "funding": [
{ {
...@@ -2680,8 +2680,8 @@ ...@@ -2680,8 +2680,8 @@
}, },
{ {
"name": "symfony/polyfill-php80", "name": "symfony/polyfill-php80",
"version": "v1.36.0", "version": "v1.37.0",
"version_normalized": "1.36.0.0", "version_normalized": "1.37.0.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-php80.git", "url": "https://github.com/symfony/polyfill-php80.git",
...@@ -2743,7 +2743,7 @@ ...@@ -2743,7 +2743,7 @@
"shim" "shim"
], ],
"support": { "support": {
"source": "https://github.com/symfony/polyfill-php80/tree/v1.36.0" "source": "https://github.com/symfony/polyfill-php80/tree/v1.37.0"
}, },
"funding": [ "funding": [
{ {
...@@ -3269,28 +3269,29 @@ ...@@ -3269,28 +3269,29 @@
}, },
{ {
"name": "workerman/phpsocket.io", "name": "workerman/phpsocket.io",
"version": "v2.2.2", "version": "v2.3.0",
"version_normalized": "2.2.2.0", "version_normalized": "2.3.0.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/walkor/phpsocket.io.git", "url": "https://github.com/walkor/phpsocket.io.git",
"reference": "5f96eace9f2bcec82555a97ac9867b732024d3b6" "reference": "eb702ce447aafb42d3390f69cdf4f9acfae673c8"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/walkor/phpsocket.io/zipball/5f96eace9f2bcec82555a97ac9867b732024d3b6", "url": "https://api.github.com/repos/walkor/phpsocket.io/zipball/eb702ce447aafb42d3390f69cdf4f9acfae673c8",
"reference": "5f96eace9f2bcec82555a97ac9867b732024d3b6", "reference": "eb702ce447aafb42d3390f69cdf4f9acfae673c8",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"ext-json": "*", "ext-json": "*",
"php": ">=7.1",
"workerman/channel": ">=1.0.0", "workerman/channel": ">=1.0.0",
"workerman/workerman": "^4.0.0" "workerman/workerman": "^4.0.0"
}, },
"require-dev": { "require-dev": {
"squizlabs/php_codesniffer": "^3.7" "squizlabs/php_codesniffer": "^3.7"
}, },
"time": "2025-04-01T08:36:37+00:00", "time": "2026-05-06T18:49:01+00:00",
"type": "library", "type": "library",
"installation-source": "dist", "installation-source": "dist",
"autoload": { "autoload": {
...@@ -3302,6 +3303,14 @@ ...@@ -3302,6 +3303,14 @@
"license": [ "license": [
"MIT" "MIT"
], ],
"authors": [
{
"name": "walkor",
"email": "walkor@workerman.net",
"homepage": "https://www.workerman.net",
"role": "Developer"
}
],
"description": "A server side alternative implementation of socket.io in PHP based on Workerman", "description": "A server side alternative implementation of socket.io in PHP based on Workerman",
"homepage": "https://www.workerman.net", "homepage": "https://www.workerman.net",
"keywords": [ "keywords": [
...@@ -3316,7 +3325,7 @@ ...@@ -3316,7 +3325,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/walkor/phpsocket.io/issues", "issues": "https://github.com/walkor/phpsocket.io/issues",
"source": "https://github.com/walkor/phpsocket.io/tree/v2.2.2" "source": "https://github.com/walkor/phpsocket.io/tree/v2.3.0"
}, },
"funding": [ "funding": [
{ {
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
'aliases' => 'aliases' =>
array ( array (
), ),
'reference' => 'd3c0b97323772b72bcb7167be81d17ea5ea513cc', 'reference' => 'a277a9d5c790c427d34713208f810f9fcb44c8b9',
'name' => 'fastadminnet/fastadmin', 'name' => 'fastadminnet/fastadmin',
), ),
'versions' => 'versions' =>
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
'aliases' => 'aliases' =>
array ( array (
), ),
'reference' => 'd3c0b97323772b72bcb7167be81d17ea5ea513cc', 'reference' => 'a277a9d5c790c427d34713208f810f9fcb44c8b9',
), ),
'fastadminnet/fastadmin-addons' => 'fastadminnet/fastadmin-addons' =>
array ( array (
...@@ -400,8 +400,8 @@ ...@@ -400,8 +400,8 @@
), ),
'symfony/polyfill-mbstring' => 'symfony/polyfill-mbstring' =>
array ( array (
'pretty_version' => 'v1.36.0', 'pretty_version' => 'v1.37.0',
'version' => '1.36.0.0', 'version' => '1.37.0.0',
'aliases' => 'aliases' =>
array ( array (
), ),
...@@ -409,8 +409,8 @@ ...@@ -409,8 +409,8 @@
), ),
'symfony/polyfill-php73' => 'symfony/polyfill-php73' =>
array ( array (
'pretty_version' => 'v1.36.0', 'pretty_version' => 'v1.37.0',
'version' => '1.36.0.0', 'version' => '1.37.0.0',
'aliases' => 'aliases' =>
array ( array (
), ),
...@@ -418,8 +418,8 @@ ...@@ -418,8 +418,8 @@
), ),
'symfony/polyfill-php80' => 'symfony/polyfill-php80' =>
array ( array (
'pretty_version' => 'v1.36.0', 'pretty_version' => 'v1.37.0',
'version' => '1.36.0.0', 'version' => '1.37.0.0',
'aliases' => 'aliases' =>
array ( array (
), ),
...@@ -509,12 +509,12 @@ ...@@ -509,12 +509,12 @@
), ),
'workerman/phpsocket.io' => 'workerman/phpsocket.io' =>
array ( array (
'pretty_version' => 'v2.2.2', 'pretty_version' => 'v2.3.0',
'version' => '2.2.2.0', 'version' => '2.3.0.0',
'aliases' => 'aliases' =>
array ( array (
), ),
'reference' => '5f96eace9f2bcec82555a97ac9867b732024d3b6', 'reference' => 'eb702ce447aafb42d3390f69cdf4f9acfae673c8',
), ),
'workerman/workerman' => 'workerman/workerman' =>
array ( array (
......
1105764
\ No newline at end of file
MIT License
Copyright (c) 2015 walkor<walkor@workerman.net> and contributors (see https://github.com/walkor/phpsocket.io/graphs/contributors)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
# phpsocket.io # phpsocket.io
A server side alternative implementation of [socket.io](https://github.com/socketio/socket.io) in PHP based on [Workerman](https://github.com/walkor/Workerman).<br>
# Notice [![Packagist Version](https://img.shields.io/packagist/v/workerman/phpsocket.io)](https://packagist.org/packages/workerman/phpsocket.io)
Only support socket.io >= v1.3.0 and <= v2.x <br> [![Total Downloads](https://img.shields.io/packagist/dt/workerman/phpsocket.io)](https://packagist.org/packages/workerman/phpsocket.io)
This project is just translate socket.io by [workerman](https://github.com/walkor/Workerman).<br> [![Monthly Downloads](https://img.shields.io/packagist/dm/workerman/phpsocket.io)](https://packagist.org/packages/workerman/phpsocket.io)
More api just see [https://socket.io/docs/v2/server-api/](https://socket.io/docs/v2/server-api/) [![PHP Version](https://img.shields.io/badge/php-%3E%3D7.1-blue)](https://www.php.net)
[![Workerman](https://img.shields.io/badge/workerman-%3E%3D4.0%20%3C5.0-orange)](https://github.com/walkor/Workerman)
[![CI](https://github.com/walkor/phpsocket.io/actions/workflows/ci.yml/badge.svg)](https://github.com/walkor/phpsocket.io/actions/workflows/ci.yml)
[![License](https://img.shields.io/packagist/l/workerman/phpsocket.io)](LICENSE)
# Install A server-side PHP implementation of [socket.io](https://github.com/socketio/socket.io) based on [Workerman](https://github.com/walkor/Workerman).
> **Notice:** Only supports socket.io client >= v1.3.0 and <= v2.x. **socket.io v3 and v4 are not supported.**
> Requires PHP >= 7.1 and Workerman >= 4.0 < 5.0. **Workerman 5.x is not supported.**
> For the full server API, see [socket.io/docs/v2/server-api](https://socket.io/docs/v2/server-api/).
## Install
```bash
composer require workerman/phpsocket.io composer require workerman/phpsocket.io
```
## Examples
### Simple chat
`start.php`
# Examples
## Simple chat
start.php
```php ```php
<?php
use Workerman\Worker; use Workerman\Worker;
use PHPSocketIO\SocketIO; use PHPSocketIO\SocketIO;
require_once __DIR__ . '/vendor/autoload.php'; require_once __DIR__ . '/vendor/autoload.php';
// Listen port 2021 for socket.io client // Listen on port 2026 for socket.io clients
$io = new SocketIO(2021); $io = new SocketIO(2026);
$io->on('connection', function ($socket) use ($io) { $io->on('connection', function ($socket) use ($io) {
$socket->on('chat message', function ($msg) use ($io) { $socket->on('chat message', function ($msg) use ($io) {
$io->emit('chat message', $msg); $io->emit('chat message', $msg);
...@@ -29,90 +46,84 @@ $io->on('connection', function ($socket) use ($io) { ...@@ -29,90 +46,84 @@ $io->on('connection', function ($socket) use ($io) {
Worker::runAll(); Worker::runAll();
``` ```
## Another chat demo ### Another chat demo
Full source: [examples/chat/start_io.php](https://github.com/walkor/phpsocket.io/blob/master/examples/chat/start_io.php)
https://github.com/walkor/phpsocket.io/blob/master/examples/chat/start_io.php
```php ```php
<?php
use Workerman\Worker; use Workerman\Worker;
use PHPSocketIO\SocketIO; use PHPSocketIO\SocketIO;
require_once __DIR__ . '/vendor/autoload.php'; require_once __DIR__ . '/vendor/autoload.php';
// Listen port 2020 for socket.io client $io = new SocketIO(2026);
$io = new SocketIO(2020);
$io->on('connection', function ($socket) { $io->on('connection', function ($socket) {
$socket->addedUser = false; $socket->addedUser = false;
// When the client emits 'new message', this listens and executes // When the client emits 'new message', this listens and executes
$socket->on('new message', function ($data) use ($socket) { $socket->on('new message', function ($data) use ($socket) {
// We tell the client to execute 'new message' $socket->broadcast->emit('new message', [
$socket->broadcast->emit('new message', array(
'username' => $socket->username, 'username' => $socket->username,
'message' => $data 'message' => $data,
)); ]);
}); });
// When the client emits 'add user', this listens and executes // When the client emits 'add user', this listens and executes
$socket->on('add user', function ($username) use ($socket) { $socket->on('add user', function ($username) use ($socket) {
// Note: global variables are used here for simplicity (demo only)
global $usernames, $numUsers; global $usernames, $numUsers;
// We store the username in the socket session for this client
$socket->username = $username; $socket->username = $username;
// Add the client's username to the global list
$usernames[$username] = $username; $usernames[$username] = $username;
++$numUsers; ++$numUsers;
$socket->addedUser = true; $socket->addedUser = true;
$socket->emit('login', array( $socket->emit('login', ['numUsers' => $numUsers]);
'numUsers' => $numUsers
));
// echo globally (all clients) that a person has connected $socket->broadcast->emit('user joined', [
$socket->broadcast->emit('user joined', array(
'username' => $socket->username, 'username' => $socket->username,
'numUsers' => $numUsers 'numUsers' => $numUsers,
)); ]);
}); });
// When the client emits 'typing', we broadcast it to others // When the client emits 'typing', broadcast it to others
$socket->on('typing', function () use ($socket) { $socket->on('typing', function () use ($socket) {
$socket->broadcast->emit('typing', array( $socket->broadcast->emit('typing', ['username' => $socket->username]);
'username' => $socket->username
));
}); });
// When the client emits 'stop typing', we broadcast it to others // When the client emits 'stop typing', broadcast it to others
$socket->on('stop typing', function () use ($socket) { $socket->on('stop typing', function () use ($socket) {
$socket->broadcast->emit('stop typing', array( $socket->broadcast->emit('stop typing', ['username' => $socket->username]);
'username' => $socket->username
));
}); });
// When the user disconnects, perform this // When the user disconnects
$socket->on('disconnect', function () use ($socket) { $socket->on('disconnect', function () use ($socket) {
global $usernames, $numUsers; global $usernames, $numUsers;
// Remove the username from global usernames list
if ($socket->addedUser) { if ($socket->addedUser) {
unset($usernames[$socket->username]); unset($usernames[$socket->username]);
--$numUsers; --$numUsers;
// echo globally that this client has left $socket->broadcast->emit('user left', [
$socket->broadcast->emit('user left', array( 'username' => $socket->username,
'username' => $socket->username, 'numUsers' => $numUsers,
'numUsers' => $numUsers ]);
));
} }
}); });
}); });
Worker::runAll(); Worker::runAll();
``` ```
## Enable SSL for https ### Enable SSL (HTTPS)
**```(phpsocket.io>=1.1.1 && workerman>=3.3.7 required)```**
> Requires phpsocket.io >= 1.1.1 and workerman >= 3.3.7
`start.php`
start.php
```php ```php
<?php <?php
...@@ -121,36 +132,37 @@ use PHPSocketIO\SocketIO; ...@@ -121,36 +132,37 @@ use PHPSocketIO\SocketIO;
require_once __DIR__ . '/vendor/autoload.php'; require_once __DIR__ . '/vendor/autoload.php';
// SSL context $context = [
$context = array( 'ssl' => [
'ssl' => array(
'local_cert' => '/your/path/of/server.pem', 'local_cert' => '/your/path/of/server.pem',
'local_pk' => '/your/path/of/server.key', 'local_pk' => '/your/path/of/server.key',
'verify_peer' => false 'verify_peer' => false,
) ],
); ];
$io = new SocketIO(2021, $context);
$io = new SocketIO(2026, $context);
$io->on('connection', function ($connection) use ($io) { $io->on('connection', function ($socket) {
echo "New connection coming\n"; echo "New connection: {$socket->id}\n";
}); });
Worker::runAll(); Worker::runAll();
``` ```
## Acknowledgement callback ### Acknowledgement callback
```php ```php
<?php
use Workerman\Worker; use Workerman\Worker;
use PHPSocketIO\SocketIO; use PHPSocketIO\SocketIO;
require_once __DIR__ . '/vendor/autoload.php'; require_once __DIR__ . '/vendor/autoload.php';
$io = new SocketIO(2021); $io = new SocketIO(2026);
$io->on('connection', function ($connection) use ($io) { $io->on('connection', function ($socket) {
$socket->on('message with ack', function ($data, $callback) use ($socket, $io) { $socket->on('message with ack', function ($data, $callback) {
// acknowledgement callback
if ($callback && is_callable($callback)) { if ($callback && is_callable($callback)) {
$callback(0); $callback(0);
} }
...@@ -160,25 +172,53 @@ $io->on('connection', function ($connection) use ($io) { ...@@ -160,25 +172,53 @@ $io->on('connection', function ($connection) use ($io) {
Worker::runAll(); Worker::runAll();
``` ```
# 手册 ## Run chat example
[中文手册](https://github.com/walkor/phpsocket.io/tree/master/docs/zh)
### With Docker
```bash
docker compose up --build
```
Then open your browser at:
- **Chat:** [http://localhost:2027](http://localhost:2027)
- **Socket.IO:** port `2026`
# Livedemo ### Without Docker
[chat demo](http://demos.workerman.net/phpsocketio-chat/)
# Run chat example ```bash
cd examples/chat cd examples/chat
```
```bash
php start.php start # debug mode
php start.php start -d # daemon mode
php start.php stop # stop
php start.php status # status
```
Then open [http://localhost:2027](http://localhost:2027) in your browser.
### Server debug output
## Start The chat example includes built-in server-side logging. When running in debug mode, connections, user activity, and messages are printed to the terminal in real time with color-coded output.
```php start.php start``` for debug mode
```php start.php start -d ``` for daemon mode ## CI
## Stop This project uses GitHub Actions to run [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) on every pull request and push to `master`, ensuring the codebase follows the coding standard defined in `phpcs.xml`.
```php start.php stop```
To run locally:
```bash
# Without Docker
composer install --dev
vendor/bin/phpcs src/
# With Docker
docker compose --profile tools run --rm phpcs
```
## Status ## License
```php start.php status```
# License [MIT](LICENSE)
MIT \ No newline at end of file
...@@ -14,7 +14,16 @@ ...@@ -14,7 +14,16 @@
], ],
"homepage": "https://www.workerman.net", "homepage": "https://www.workerman.net",
"license": "MIT", "license": "MIT",
"authors": [
{
"name": "walkor",
"email": "walkor@workerman.net",
"homepage": "https://www.workerman.net",
"role": "Developer"
}
],
"require": { "require": {
"php": ">=7.1",
"workerman/workerman": "^4.0.0", "workerman/workerman": "^4.0.0",
"workerman/channel": ">=1.0.0", "workerman/channel": ">=1.0.0",
"ext-json": "*" "ext-json": "*"
......
...@@ -39,7 +39,7 @@ class Parser ...@@ -39,7 +39,7 @@ class Parser
public static function encodePacket($packet): string public static function encodePacket($packet): string
{ {
$data = ! isset($packet['data']) ? '' : $packet['data']; $data = $packet['data'] ?? '';
return self::$packets[$packet['type']] . $data; return self::$packets[$packet['type']] . $data;
} }
......
...@@ -37,15 +37,15 @@ class Request ...@@ -37,15 +37,15 @@ class Request
public function parseHead($raw_head) public function parseHead($raw_head)
{ {
$header_data = explode("\r\n", $raw_head); $header_data = explode("\r\n", $raw_head);
list($this->method, $this->url, $protocol) = explode(' ', $header_data[0]); [$this->method, $this->url, $protocol] = explode(' ', $header_data[0]);
list($null, $this->httpVersion) = explode('/', $protocol); [, $this->httpVersion] = explode('/', $protocol);
unset($header_data[0]); unset($header_data[0]);
foreach ($header_data as $content) { foreach ($header_data as $content) {
if (empty($content)) { if (empty($content)) {
continue; continue;
} }
$this->rawHeaders[] = $content; $this->rawHeaders[] = $content;
list($key, $value) = explode(':', $content, 2); [$key, $value] = explode(':', $content, 2);
$this->headers[strtolower($key)] = trim($value); $this->headers[strtolower($key)] = trim($value);
} }
} }
......
...@@ -163,7 +163,7 @@ class SocketIO ...@@ -163,7 +163,7 @@ class SocketIO
if (isset($connection->onRequest)) { if (isset($connection->onRequest)) {
return $http_buffer; return $http_buffer;
} else { } else {
list($head, $body) = explode("\r\n\r\n", $http_buffer, 2); [$head, $body] = explode("\r\n\r\n", $http_buffer, 2);
return $body; return $body;
} }
} }
......
...@@ -84,8 +84,7 @@ class RFC6455 implements ProtocolInterface ...@@ -84,8 +84,7 @@ class RFC6455 implements ProtocolInterface
// 如果有设置onWebSocketClose回调,尝试执行 // 如果有设置onWebSocketClose回调,尝试执行
if (isset($connection->onWebSocketClose)) { if (isset($connection->onWebSocketClose)) {
call_user_func($connection->onWebSocketClose, $connection); call_user_func($connection->onWebSocketClose, $connection);
} // 默认行为是关闭连接 } else { // 默认行为是关闭连接
else {
$connection->close(); $connection->close();
} }
return 0; return 0;
...@@ -94,8 +93,7 @@ class RFC6455 implements ProtocolInterface ...@@ -94,8 +93,7 @@ class RFC6455 implements ProtocolInterface
// 如果有设置onWebSocketPing回调,尝试执行 // 如果有设置onWebSocketPing回调,尝试执行
if (isset($connection->onWebSocketPing)) { if (isset($connection->onWebSocketPing)) {
call_user_func($connection->onWebSocketPing, $connection); call_user_func($connection->onWebSocketPing, $connection);
} // 默认发送pong } else { // 默认发送pong
else {
$connection->send(pack('H*', '8a00'), true); $connection->send(pack('H*', '8a00'), true);
} }
// 从接受缓冲区中消费掉该数据包 // 从接受缓冲区中消费掉该数据包
...@@ -154,16 +152,14 @@ class RFC6455 implements ProtocolInterface ...@@ -154,16 +152,14 @@ class RFC6455 implements ProtocolInterface
$connection->consumeRecvBuffer($connection->websocketCurrentFrameLength); $connection->consumeRecvBuffer($connection->websocketCurrentFrameLength);
$connection->websocketCurrentFrameLength = 0; $connection->websocketCurrentFrameLength = 0;
return 0; return 0;
} // 收到的数据大于一个frame } elseif ($connection->websocketCurrentFrameLength < $recv_len) { // 收到的数据大于一个frame
elseif ($connection->websocketCurrentFrameLength < $recv_len) {
self::decode(substr($buffer, 0, $connection->websocketCurrentFrameLength), $connection); self::decode(substr($buffer, 0, $connection->websocketCurrentFrameLength), $connection);
$connection->consumeRecvBuffer($connection->websocketCurrentFrameLength); $connection->consumeRecvBuffer($connection->websocketCurrentFrameLength);
$current_frame_length = $connection->websocketCurrentFrameLength; $current_frame_length = $connection->websocketCurrentFrameLength;
$connection->websocketCurrentFrameLength = 0; $connection->websocketCurrentFrameLength = 0;
// 继续读取下一个frame // 继续读取下一个frame
return self::input(substr($buffer, $current_frame_length), $connection); return self::input(substr($buffer, $current_frame_length), $connection);
} // 收到的数据不足一个frame } else { // 收到的数据不足一个frame
else {
return 0; return 0;
} }
} }
......
...@@ -59,7 +59,7 @@ class Socket extends Emitter ...@@ -59,7 +59,7 @@ class Socket extends Emitter
public function onUpgradePacket(array $packet): void public function onUpgradePacket(array $packet): void
{ {
if (empty($this->upgradeTransport)) { if (empty($this->upgradeTransport)) {
$this->onError('upgradeTransport empty'); $this->onError('Upgrade transport is not available or was already cleared');
return; return;
} }
if ('ping' === $packet['type'] && (isset($packet['data']) && 'probe' === $packet['data'])) { if ('ping' === $packet['type'] && (isset($packet['data']) && 'probe' === $packet['data'])) {
...@@ -103,7 +103,7 @@ class Socket extends Emitter ...@@ -103,7 +103,7 @@ class Socket extends Emitter
public function onUpgradeTransportClose(): void public function onUpgradeTransportClose(): void
{ {
$this->onUpgradeTransportError('transport closed'); $this->onUpgradeTransportError('Upgrade transport closed unexpectedly');
} }
public function onUpgradeTransportError($err): void public function onUpgradeTransportError($err): void
......
...@@ -41,7 +41,7 @@ class Transport extends Emitter ...@@ -41,7 +41,7 @@ class Transport extends Emitter
public function onError(string $msg, string $desc = '') public function onError(string $msg, string $desc = '')
{ {
if ($this->listeners('error')) { if ($this->listeners('error')) {
$this->emit('error', "TransportError: {$desc}"); $this->emit('error', "TransportError: {$msg}" . ($desc ? " - {$desc}" : ''));
} else { } else {
echo("ignored transport error $msg $desc\n"); echo("ignored transport error $msg $desc\n");
} }
......
...@@ -32,7 +32,7 @@ class Polling extends Transport ...@@ -32,7 +32,7 @@ class Polling extends Transport
public function onPollRequest(object $req, object $res): void public function onPollRequest(object $req, object $res): void
{ {
if ($this->req) { if ($this->req) {
$this->onError('overlap from client'); $this->onError('Overlap from client', 'A poll request already exists for this transport');
$res->writeHead(500); $res->writeHead(500);
return; return;
} }
...@@ -54,7 +54,7 @@ class Polling extends Transport ...@@ -54,7 +54,7 @@ class Polling extends Transport
public function pollRequestOnClose(): void public function pollRequestOnClose(): void
{ {
$this->onError('poll connection closed prematurely'); $this->onError('Poll connection closed prematurely', 'Client disconnected before poll response was sent');
$this->pollRequestClean(); $this->pollRequestClean();
} }
...@@ -69,7 +69,7 @@ class Polling extends Transport ...@@ -69,7 +69,7 @@ class Polling extends Transport
public function onDataRequest($req, $res): void public function onDataRequest($req, $res): void
{ {
if (isset($this->dataReq)) { if (isset($this->dataReq)) {
$this->onError('data request overlap from client'); $this->onError('Data request overlap from client', 'A data request already exists for this transport');
$res->writeHead(500); $res->writeHead(500);
return; return;
} }
...@@ -91,7 +91,7 @@ class Polling extends Transport ...@@ -91,7 +91,7 @@ class Polling extends Transport
public function dataRequestOnClose(): void public function dataRequestOnClose(): void
{ {
$this->dataRequestCleanup(); $this->dataRequestCleanup();
$this->onError('data request connection closed prematurely'); $this->onError('Data request connection closed prematurely', 'Client disconnected before data request completed');
} }
public function dataRequestOnData($req, $data): void public function dataRequestOnData($req, $data): void
......
...@@ -26,7 +26,7 @@ class PollingJsonp extends Polling ...@@ -26,7 +26,7 @@ class PollingJsonp extends Polling
$parsed_data = null; $parsed_data = null;
parse_str($data, $parsed_data); parse_str($data, $parsed_data);
$data = $parsed_data['d']; $data = $parsed_data['d'];
call_user_func(array(get_parent_class($this), 'onData'), preg_replace('/\\\\n/', '\\n', $data)); call_user_func([get_parent_class($this), 'onData'], preg_replace('/\\\\n/', '\\n', $data));
} }
public function doWrite($data): void public function doWrite($data): void
......
...@@ -31,13 +31,12 @@ class WebSocket extends Transport ...@@ -31,13 +31,12 @@ class WebSocket extends Transport
public function onData2($connection, $data): void public function onData2($connection, $data): void
{ {
call_user_func(array(get_parent_class($this), 'onData'), $data); call_user_func([get_parent_class($this), 'onData'], $data);
} }
public function onError2($conection, $code, $msg): void public function onError2($conection, $code, $msg): void
{ {
call_user_func(array(get_parent_class($this), 'onData'), $code, $msg); call_user_func([get_parent_class($this), 'onData'], $code, $msg);
} }
public function send(array $packets): void public function send(array $packets): void
......
...@@ -98,7 +98,7 @@ class Socket extends Emitter ...@@ -98,7 +98,7 @@ class Socket extends Emitter
{ {
$args = func_get_args(); $args = func_get_args();
if (isset(self::$events[$ev])) { if (isset(self::$events[$ev])) {
call_user_func_array(array(get_parent_class(__CLASS__), 'emit'), $args); call_user_func_array([get_parent_class(__CLASS__), 'emit'], $args);
} else { } else {
$packet = []; $packet = [];
$packet['type'] = Parser::EVENT; $packet['type'] = Parser::EVENT;
...@@ -295,7 +295,7 @@ class Socket extends Emitter ...@@ -295,7 +295,7 @@ class Socket extends Emitter
if (! empty($packet['id']) || (isset($packet['id']) && $packet['id'] === 0)) { if (! empty($packet['id']) || (isset($packet['id']) && $packet['id'] === 0)) {
$args[] = $this->ack($packet['id']); $args[] = $this->ack($packet['id']);
} }
call_user_func_array(array(get_parent_class(__CLASS__), 'emit'), $args); call_user_func_array([get_parent_class(__CLASS__), 'emit'], $args);
} }
/** /**
......
a:1:{i:1105765;a:2:{s:4:"name";s:16:"ShoproChatWorker";s:6:"listen";s:23:"socketIO://0.0.0.0:2222";}}
----------------------------------------------GLOBAL STATUS----------------------------------------------------
Workerman version:4.1.17 PHP version:7.4.33
start time:2026-05-11 14:16:08 run 0 days 0 hours
load average: 0.01, 0.02, 0 event-loop:\Workerman\Events\Select
1 workers 1 processes
worker_name exit_status exit_count
ShoproChatWorker 0 0
----------------------------------------------PROCESS STATUS---------------------------------------------------
pid memory listening worker_name connections send_fail timers total_request qps status
1105765 4.79M socketIO://0.0.0.0:2222 ShoproChatWorker 0 0 2 0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment