Giter Club home page Giter Club logo

easyswoole's Introduction

English | 中文

Latest Stable Version Total Downloads Latest Unstable Version License Monthly Downloads

EasySwoole - A High Performance Swoole Framework

EasySwoole is a distributed, persistent memory PHP framework based on the Swoole extension. It was created specifically for APIs to get rid of the performance penalties associated with process calls and file loading. EasySwoole highly encapsulates the Swoole Server and still maintains the original features of the Swoole server, supports simultaneous monitoring of HTTP, custom TCP, and UDP protocols, allowing developers to write multi-process, asynchronous, and highly available applications with minimal learning cost and effort.

  • Base on Swoole extension
  • Built-in HTTP, TCP, WebSocket,Udp Coroutine Server
  • Global dependency injection container
  • PSR-7 based HTTP message implementation
  • HTTP,TCP, WebSocket, Udp middleware support
  • Scalable high performance RPC
  • Database ORM
  • Mysql, Redis, RPC, HTTP Coroutine Clients
  • Coroutine and asynchronous task delivery
  • Custom user processes
  • RESTful supported
  • High performance router
  • Fast and flexible parameter validator
  • Powerful log component
  • Universal connection pools
  • Remote Console support
  • Crontab Rule Timer support

Doc

ab Test

<?php

namespace App\HttpController;

use EasySwoole\Http\AbstractInterface\Controller;


/**
 * Class Index
 * @package App\HttpController
 */
class Index extends Controller
{
    public function index()
    {
        $this->response()->write('Hello World');
    }
}

1 Core 1G RAM

command : ab -c 100 -n 10000 http://192.168.0.11:9501/

Server Software:        EasySwoole
Server Hostname:        192.168.0.11
Server Port:            9501

Document Path:          /
Document Length:        21 bytes

Concurrency Level:      100
Time taken for tests:   0.652 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      1690000 bytes
HTML transferred:       210000 bytes
Requests per second:    15325.16 [#/sec] (mean)
Time per request:       9.685 [ms] (mean)
Time per request:       0.097 [ms] (mean, across all concurrent requests)
Transfer rate:          2592.05 [Kbytes/sec] received

8 Core 16G RAM

command : ab -c 100 -n 10000 http://192.168.0.4:9501/

Server Software:        EasySwoole
Server Hostname:        192.168.0.4
Server Port:            9501

Document Path:          /
Document Length:        21 bytes

Concurrency Level:      100
Time taken for tests:   0.746 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      1690000 bytes
HTML transferred:       210000 bytes
Requests per second:    66935.97 [#/sec] (mean)
Time per request:       1.149 [ms] (mean)
Time per request:       0.015 [ms] (mean, across all concurrent requests)
Transfer rate:          2265.40 [Kbytes/sec] received

Quick Start

composer require easyswoole/easyswoole=3.7.x
php vendor/bin/easyswoole.php install
php easyswoole.php server start

Docker

Get Docker Image

docker pull easyswoolexuesi2021/easyswoole:php8.1.22-alpine3.16-swoole4.8.13

More Docker images can be viewed:Docker Hub or Git for Dockerfile

Run

docker run --name easyswoole \
-v /workspace/project:/var/www/project \
-p 9501:9501 -it \
--privileged -u root \
--entrypoint /bin/sh \
easyswoolexuesi2021/easyswoole:php8.1.22-alpine3.16-swoole4.8.13
  • WorkerDir: /var/www
  • Run Easyswoole :
composer require easyswoole/easyswoole=3.7.x
php vendor/bin/easyswoole.php install
php easyswoole.php server start

Others

  • Git For Demo

  • QQ交流群

    • VIP群 579434607 (本群需要付费599元)
    • EasySwoole官方一群 633921431(已满)
    • EasySwoole官方二群 709134628(已满)
    • EasySwoole官方三群 932625047(已满)
    • EasySwoole官方四群 779897753(已满)
    • EasySwoole官方五群 853946743(已满)
    • EasySwoole官方六群 524475224
  • 商业支持:

easyswoole's People

Contributors

137-rick avatar 2pgcn avatar acrossmountain avatar anythink-wx avatar chrisleeareemm avatar davidzhang12138 avatar encircles avatar evalor avatar hanwenbo avatar heelie avatar huizhang001 avatar iamvar avatar joyboo avatar kajweb avatar kiss291323003 avatar no-serve-people avatar osindex avatar pandasir avatar pppscn avatar stitch-june avatar sy-records avatar tim1116 avatar tioncico avatar wandoubaba avatar wi1dcard avatar willove avatar windrunner414 avatar xuanyanwow avatar xuesilf avatar xuhaoxian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

easyswoole's Issues

The easyswoole-wrapped coroutine HTTP client does not provide a set method

Easyswoole packaged coroutine HTTP client, I found no set method, such as $ client-> set (['timeout' => 1]); so now directly using easyswoole http client, want to set the timeout, etc. configuration only Can I add a set to the frame source easyswoole/src/Core/Swoole/Coroutine/Client/Http.php?

TCPSERVER默认没有监听onReceive,onPacket函数

在脚本启动时,根据配置文件要实例化server类型,当配置为tcpserver时,没有监听OnReceive,onPacket方法。在EventHelper中已经有这些方法的定义,但没有找到在什么地方调用。

测试报告

我是实时拉取github代码测的

  • frameInitialized 加载两次
  • ServerManager coroutineId 有一次返回的不是int也不是null,但从代码来看不太可能,导致php有提示 具体提示没保存,稍后再测试,我记得大体意思就是这个结果不规范
  • ROOT composer/bin/easyswoole 里定义了 这意味着外面无法把 Log Temp 定义在vendor外,或者说我的代码里也会用到ROOT,这是个常用的名字 可在vendor里占用了 不友好
  • 【加急】ERROR_HANDLER 定义无效,或者我用法不对
  • http和websocket共用不了
  • 问下:2.x里Request没有getInstance了 测试需要先以什么方法获取为准?
    暂时这些 因为更新了代码跑不起来 临时停止测试 发现群主新提交后再进行更新测试

DefaultPackageParser导致RPC问题

DefaultPackageParser的encode和decode使用了base_convert,导致RPC的service收到的Package有问题。测试时将base_convert去掉后,RPC正常调用了。
image

swoole version 2.0.10
easyswoole version 1.1.1
PHP:
PHP 7.0.18-0ubuntu0.16.10.1 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.18-0ubuntu0.16.10.1, Copyright (c) 1999-2017, by Zend Technologies

ES USES the PDO to cause service exceptions

swoole for win版本:https://www.swoole.com/static/swoole-4.2.1.zip
es版本:1.1.1

问题:在直接运行php和使用swoole运行pdo均正常。但是在es中使用出现了502错误(无法访问此网站)。同样的es代码在linux可以正常运行,但在win版本无法运行。

<?php
//php-cli Version(正常)
$dbhost = '127.0.0.1:3306';  // mysql服务器主机地址
$dbuser = 'admin';            // mysql用户名
$dbpass = 'admin';          // mysql用户名密码
$conn = new PDO('mysql:host=127.0.0.1;dbname=yiban;port=3306', $dbuser, $dbpass );
$query = $conn->query('select * from yiban_college_data');
$data =[];
print_r( $query->fetchAll() );
<?php
//php-swoole Version(正常)
$http = new swoole_http_server("127.0.0.1", 9501);
$http->on('request', function ($request, $response) {
	$dbhost = '127.0.0.1:3306';  // mysql服务器主机地址
	$dbuser = 'admin';            // mysql用户名
	$dbpass = 'admin';          // mysql用户名密码
	$conn = new PDO('mysql:host=127.0.0.1;dbname=yiban;port=3306', $dbuser, $dbpass );
	$query = $conn->query('select * from yiban_college_data');
	$data =[];
	print_r( $query->fetchAll() );
    $response->end("<h1>Hello Swoole. #".rand(1000, 9999)."</h1>");
});
$http->start();
<?php
//ES Version(win异常,linux正常)
    function test(){
        $dbhost = '127.0.0.1:3306';  // mysql服务器主机地址
        $dbuser = 'admin';            // mysql用户名
        $dbpass = 'admin';          // mysql用户名密码
        $conn = new \PDO('mysql:host=127.0.0.1;dbname=yiban;port=3306', $dbuser, $dbpass );
        $query = $conn->query('select * from yiban_college_data');
        $data =[];
        print_r( $query->fetchAll() );
    }

测试记录 2.x-dev

composer 、 mac环境、php7.2

以下记录从体验者角度来反馈:

  • 运行composer时提示让easyswoole install,操作完了大概是没权限提示一下错误
    PHP Warning: mkdir(): Invalid path in /Volumes/dev/www/fashop-swoole/vendor/easyswoole/easyswoole/src/Core/Utility/File.php on line 20
    Warning: mkdir(): Invalid path in /Volumes/dev/www/fashop-swoole/vendor/easyswoole/easyswoole/src/Core/Utility/File.php on line 20
    create Temp Directory: fail

暂时没有文档的原因,先记录

  • 体验上来说这个install不是有友好,大多开发者以为composer完事就真完事了,这儿还需要进入到bin里去找easyswoole,然后第一感觉是运行easyswoole install 结果发现没有,其实是需要php easyswoole install,但注意了 对于刚尝试的人不太理解

建议:改成 php easyswoole install,关于替换那个replace it 去掉,因为哥一抖 给替换了,不知道其他人是否会遇到

fizz都已经解决不再记录

异常处理、非致命错误的体验优化建议。

这块呢,通过我使用,我发现新用户调试很吃力,由于用了tp或其他框架,都有异常处理 大伙对异常处理的了解就少,es warning错误会显示在页面上,调试节奏慢,这时大家就卡壳了 需要去封装异常处理。
我觉得不如让非致命的、异常的默认不要在页面上显示,让大家先用起来,让其去快速流程的实现功更有乐趣和成就感。
随着社区的发展,轮子多了,大家在看个人爱好去装自己喜好的异常处理依赖。

以上仅代表个人观点,具体处理方式还需要群主根据大局来权衡。

简单qps测试;没有啥亮点?

➜  swoole curl http://127.0.0.1:9501/test
this is index test%                                                                                                       ➜  swoole
➜  swoole wrk -t 2 -c 1000 -d 10 http://127.0.0.1:9501/test
Running 10s test @ http://127.0.0.1:9501/test
  2 threads and 1000 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     1.16s   430.52ms   1.69s    54.32%
    Req/Sec   224.37     46.09   370.00     75.38%
  4466 requests in 10.04s, 828.65KB read
  Socket errors: connect 0, read 992, write 3, timeout 0
Requests/sec:    444.83
Transfer/sec:     82.54KB
➜  swoole
➜  swoole wrk -t 2 -c 1000 -d 10 http://127.0.0.1:9501/test
Running 10s test @ http://127.0.0.1:9501/test
  2 threads and 1000 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     1.18s   444.71ms   1.75s    57.03%
    Req/Sec   222.19     53.77   390.00     75.88%
  4429 requests in 10.07s, 821.79KB read
  Socket errors: connect 0, read 967, write 2, timeout 0
Requests/sec:    439.89
Transfer/sec:     81.62KB
➜  swoole

为何测试qps 这么低了;默认启动方式; 4 worker形式;
环境
mac osx 4 GB 1600 MHz DDR3 i5 双核;
以上是纯粹echo xxxxx;
php-fpm 同样逻辑echo xxx qps 900;;和你之前的贴出的数据相比差异蛮大的;
你能否针对你的机器 弄个php-fpm /swoole 弄个同样逻辑的数字对比了?

【建议】serverStop命令等待时间根据max_wait_time设置,兼容异步安全重启特性

使用背景

'SETTING' => [
            'task_worker_num' => 8, //异步任务进程
            'task_max_request' => 10,
            'max_request' => 5000, //强烈建议设置此配置项
            'worker_num' => 8,
            'reload_async' => true, // 支持异步安全重启特性 https://wiki.swoole.com/wiki/page/775.html
            'max_wait_time' => 30, // Worker进程最大等待时间,默认为30秒
        ],

为了保证 reload, stop, restart 场景不会中断处理中的请求,通常会设置reload_async & max_wait_time

实际情况

php easyswoole stop
#!/usr/bin/env php
stop server fail.try -f again 

由于serverStop方法中写死了执行等待时间为5s所以出现上述的情况,不过在停止服务时这个情况无伤大雅,因为过一会worker也会结束,或者达到max_wait_time被强制结束。

但在restart的场景下serverStop只等待5s,导致serverStart并没有被执行到。

建议

是否可以考虑serverStop的等待时间可根据max_wait_time配置,如果没有配置,则默认30s。

启动脚本Bug:php server start --d

依次执行:
php server start --d
php server stop
php server reload --d

第三条的命令直接报错,找不到 pid 文件,建议:无用是否启用守护进程,都要保存 pid

另外,

  1. 调试场景下,在系统内存不足时,无法启动worker/tasker进程,而manager进程倒是增加了几个;
  2. xshell 执行 php server start 即不使用守护进程模式,(午饭后)过段时间后,xshell 断开了ssh连接,重新连接进服务器,ps aux|grep swoole 进程还在,只是无法用 php server stop 杀死,只能用 kill 命令。

建议优化 stop 部分的脚本,尤其是在没有 --d 时:
ps aux|grep swoole |grep -v |cut -c 9-15 | xargs kill -9

ps -ef|grep swoole|grep -v grep|awk '{print "kill -9 " $2}' | balabalabalalbalabala

一点小建议

给bin下面的easyswoole开头加上#!/usr/bin/env php,可以使得phpstorm高亮

启动进程的时候能否标明是什么进程?

配置8个work , 8个task_work, 启动进程后有19个进程
全部都显示:vendor/bin/easyswoole start
后来在群里才知道多了个cache 进程
能否支持 启动进程后查看进程显示是master manager cache worker 进程,如:
vendor/bin/easyswoole master start
vendor/bin/easyswoole manager start

composer

不考虑支持一下composer么?

无法响应较大的文件

$this->response->withBody(new \Core\Http\Message\Stream(fopen($path,'r')));

mmap() failed: [12] Cannot allocate memory
PHP Fatal error: Out of memory (allocated 2150281216) (tried to allocate 2146088960 bytes)

求大神考虑

框架对小写的支持,比如:App写成app Core写成core
注意:server的update更新Core的目录
以及Controller的大小写,我记得我最初改过,不过由于小写无法识别Controller的路径了还是咋的 放弃了

需求总结下:
1.文件夹大小写自定义支持

About coroutine mysql connection pool

When using easyswoole's coroutine MySQL connection pool, when I use a $db to execute two statements, it will complain "mysql client is waiting response, cannot send new sql query."

没人提issues

我怕你寂寞。
话说,阿里云clone好慢。。。而且。。。我还在用1.x怎么办。建议把master改名为1.x?

自动加载配置的文档有点小问题

public static function frameInitialize(): void
    {
        date_default_timezone_set('Asia/Shanghai');
        // 载入项目 Conf 文件夹中所有的配置文件
        $this->loadConf(EASYSWOOLE_ROOT . '/Conf');
    }

这里不能用 $this
$this->loadConf(EASYSWOOLE_ROOT . '/Conf'); 应该改为 (new self())->loadConf(EASYSWOOLE_ROOT . '/Conf');

无法使用 Cache 是什么原因

刚开始可以使用
Cache::getInstance()->set('token','test');

调试了多次后就再也不能使用了

swoole.log
会出现如下错误
[2018-09-27 16:41:04 $6825.0] WARNING swManager_check_exit_status: worker#5 abnormal exit, status=0, signal=11

开发环境如下:

swoole version 2.0.7
php version 7.2.1
MacBook Pro 10.14

官网文档框架安装下有一项报错处理

在一些环境中,特别是使用集成面板安装的 PHP 环境,会出现以下报错……

我使用宝塔面板进行安装,确实出现了上述问题,在面板中把php的禁用函数去掉就可以了,我并没有去细查哪个函数被禁用导致安装失败,但是我不禁用函数的情况下是可以同时使用easyswoole和宝塔面板的,希望作者写到手册中,让更多面板用户可以使用easyswoole

Scalable Datascraper

Hello,
i'm trying to understand how easyswoole can help me upgrading my distributed datascraper achitecture which i built on top of zeromq (majordomo pattern + optional titanic queue persistence on redis), msgpack for network packet compression and mongodb for schema-less storage.

With zeromq i can setup a main majordomo broker that maintain a list of available workers identified by names and distributed across multiple machines, creating a pool of each worker type. Using a vent-sink pattern i push the tasks that need to be performed and these are distributed across the workers as they become available (these are single thread workers, so while working they don't respond to heartbeat and from the broker point of view they become unavailable, and return available after the task is done and the heartbeat is restored).
The tasks distribution is not following the round robin approach, since the workers internal zmq queue is limited to 1 task and the broker recieve a "task done" aknowledge , so the fastest workers got more tasks todo.

What i love of this approach is that is resilent and consistent, broker down ? no problem, it restart (as it is supervisor monitored) and process the "eventually" persisted titanic queue.
Need more processing power? No problem, spin-up a new node with 100 workers and they immediatly starts working.

What i hate is the memory consumption, each worker requires between 15 to 30 mb, and also the relevant quantity of php code distributed on each worker (the majordomo pattern, titanic and majordomo worker code is written in php, same as the redis queue and few other stuff).

I'd like to hear your opinion about the benefits rewriting this kind of architecture using easyswoole/swoole. Some examples will be very appreciated.

Beg my pardon for my bad english, hope can help me better understand.
thank you!

Fatal error: Cannot make static method EasySwoole\Core\AbstractInterface\EventInterface::frameInitialize() non static in class EasySwoole\EasySwooleEvent

Fatal error: Cannot make static method EasySwoole\Core\AbstractInterface\EventInterface::frameInitialize() non static in class EasySwoole\EasySwooleEvent in /var/www/easyswooleySwooleEvent.php on line 18
用docker自定义镜像 php7.2 swoole2.1.3
报这个错了 请问怎么解决呢? 如果改Interface那个接口 把static去掉 会不会影响整个框架的运行呢?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.