GithubHelp home page GithubHelp logo

simple-swoole / simps Goto Github PK

View Code? Open in Web Editor NEW
466.0 24.0 48.0 92 KB

🚀 A simple, lightweight and high-performance PHP coroutine framework.

Home Page: https://simps.io

License: Apache License 2.0

PHP 100.00%
swoole-framework http websocket mqtt swoole simps tcp server udp coroutine

simps's Introduction

English | 中文

Simps

Simps

Simps License Latest Version Contact Simps Team PHP Version Swoole Version Join Discord community and chat about Simps

🚀 A simple, lightweight and high-performance PHP coroutine framework.

Benchmark

Benchmark testing performance ranking ahead of web frameworks in Java, Go, Python and other languages.

See https://github.com/the-benchmarker/web-frameworks

Support Features

  • HTTP Server
  • WebSocket Server
  • TCP Server
  • UDP Server
  • MQTT Server/Client

Documentation

https://doc.simps.io

Contribution

Your contribution to Simps development is very welcome!

You may contribute in the following ways:

Contributors

This project exists thanks to all the people who contribute. [Contributors].

License

Apache License Version 2.0 see http://www.apache.org/licenses/LICENSE-2.0.html

simps's People

Contributors

djw1028769140 avatar easydowork avatar gxhua avatar inspurhua avatar koooooo-7 avatar maximium avatar shenzhe avatar sy-records 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

simps's Issues

[Doc] More about servers.php

Would you please add more information about servers.php, like complete Http example be with the parameters description.

medoo 如何整合

我看了文档,说 Medoo 应该继承于 BaseModel,这样的话,我遇到的问题是,实例化他们的参数不一样,是不是还要做另外的封装

websocket 支持ipv6问题

ws服务启动的时候 没有像http一样增加sock_type的定义
$this->_server = new Server($wsConfig['ip'], $wsConfig['port'], $config['mode']);
默认应该是SWOOLE_SOCK_TCP这个不支持ipv6
在配置里的sock_type 在这里没有加入执行.

Multiple databases

How to connect to multiple databases?
config/database.php only the pool to one database is calculated.

Simps\DB\BaseModel 用于协程服务报错

报错日志

string(19) "onWorkerStart error"
array(4) {
  ["type"]=>
  int(1)
  ["message"]=>
  string(936) "Uncaught PDOException: Cannot execute queries while other unbuffered queries are active.  Consider using PDOStatement::fetchAll().  Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute. in @swoole-src/library/core/Database/PDOProxy.php:64
Stack trace:
#0 /alidata/www/tournament/vendor/simple-swoole/db/src/BaseModel.php(1352): Swoole\Database\PDOProxy->__call()
#1 /alidata/www/tournament/vendor/simple-swoole/db/src/BaseModel.php(131): Simps\DB\BaseModel->realGetConn()
#2 /alidata/www/tournament/vendor/simple-swoole/db/src/BaseModel.php(491): Simps\DB\BaseModel->exec()
#3 /alidata/www/tournament/app/Gateway.php(104): Simps\DB\BaseModel->get()
#4 /alidata/www/tournament/app/Server.php(480): Game\App\Gateway::getPlayerData()
#5 /alidata/www/tournament/app/Server.php(319): Game\App\Server->joinGameRoom()
#6 {main}
  thrown"
  ["file"]=>
  string(46) "@swoole-src/library/core/Database/PDOProxy.php"
  ["line"]=>
  int(64)
}
errCode: 0, errMsg: Success
string(15) "debug_backtrace"
array(1) {
  [0]=>
  array(5) {
    ["function"]=>
    string(18) "Game\App\{closure}"
    ["class"]=>
    string(15) "Game\App\Server"
    ["object"]=>
    object(Game\App\Server)#3 (1) {
      ["server":"Game\Core\BaseServer":private]=>
      object(Swoole\WebSocket\Server)#2 (26) {
        ["onStart":"Swoole\Server":private]=>
        array(2) {
          [0]=>
          *RECURSION*
          [1]=>
          string(7) "onStart"
        }
        ["onShutdown":"Swoole\Server":private]=>
        NULL
        ["onWorkerStart":"Swoole\Server":private]=>
        array(2) {
          [0]=>
          *RECURSION*
          [1]=>
          string(13) "onWorkerStart"
        }
        ["onWorkerStop":"Swoole\Server":private]=>
        array(2) {
          [0]=>
          *RECURSION*
          [1]=>
          string(12) "onWorkerStop"
        }
        ["onBeforeReload":"Swoole\Server":private]=>
        NULL
        ["onAfterReload":"Swoole\Server":private]=>
        NULL
        ["onWorkerExit":"Swoole\Server":private]=>
        array(2) {
          [0]=>
          *RECURSION*
          [1]=>
          string(12) "onWorkerExit"
        }
        ["onWorkerError":"Swoole\Server":private]=>
        array(2) {
          [0]=>
          *RECURSION*
          [1]=>
          string(13) "onWorkerError"
        }
        ["onTask":"Swoole\Server":private]=>
        array(2) {
          [0]=>
          *RECURSION*
          [1]=>
          string(6) "onTask"
        }
        ["onFinish":"Swoole\Server":private]=>
        array(2) {
          [0]=>
          *RECURSION*
          [1]=>
          string(8) "onFinish"
        }
        ["onManagerStart":"Swoole\Server":private]=>
        array(2) {
          [0]=>
          *RECURSION*
          [1]=>
          string(14) "onManagerStart"
        }
        ["onManagerStop":"Swoole\Server":private]=>
        NULL
        ["onPipeMessage":"Swoole\Server":private]=>
        NULL
        ["setting"]=>
        array(16) {
          ["max_request"]=>
          int(0)
          ["worker_num"]=>
          int(1)
          ["task_worker_num"]=>
          int(2)
          ["dispatch_mode"]=>
          int(5)
          ["hook_flags"]=>
          int(2147479551)
          ["enable_coroutine"]=>
          bool(true)
          ["task_enable_coroutine"]=>
          bool(true)
          ["max_wait_time"]=>
          int(15)
          ["reload_async"]=>
          bool(true)
          ["output_buffer_size"]=>
          int(4294967295)
          ["max_connection"]=>
          int(1024)
          ["open_http_protocol"]=>
          bool(true)
          ["open_mqtt_protocol"]=>
          bool(false)
          ["open_eof_check"]=>
          bool(false)
          ["open_length_check"]=>
          bool(false)
          ["open_websocket_protocol"]=>
          bool(true)
        }
        ["connections"]=>
        object(Swoole\Connection\Iterator)#6 (0) {
        }
        ["host"]=>
        string(7) "0.0.0.0"
        ["port"]=>
        int(9502)
        ["type"]=>
        int(1)
        ["mode"]=>
        int(2)
        ["ports"]=>
        array(1) {
          [0]=>
          object(Swoole\Server\Port)#4 (16) {
            ["onConnect":"Swoole\Server\Port":private]=>
            NULL
            ["onReceive":"Swoole\Server\Port":private]=>
            NULL
            ["onClose":"Swoole\Server\Port":private]=>
            array(2) {
              [0]=>
              *RECURSION*
              [1]=>
              string(7) "onClose"
            }
            ["onPacket":"Swoole\Server\Port":private]=>
            NULL
            ["onBufferFull":"Swoole\Server\Port":private]=>
            NULL
            ["onBufferEmpty":"Swoole\Server\Port":private]=>
            NULL
            ["onRequest":"Swoole\Server\Port":private]=>
            NULL
            ["onHandShake":"Swoole\Server\Port":private]=>
            NULL
            ["onOpen":"Swoole\Server\Port":private]=>
            array(2) {
              [0]=>
              *RECURSION*
              [1]=>
              string(6) "onOpen"
            }
            ["onMessage":"Swoole\Server\Port":private]=>
            array(2) {
              [0]=>
              *RECURSION*
              [1]=>
              string(9) "onMessage"
            }
            ["host"]=>
            string(7) "0.0.0.0"
            ["port"]=>
            int(9502)
            ["type"]=>
            int(1)
            ["sock"]=>
            int(3)
            ["setting"]=>
            array(9) {
              ["max_request"]=>
              int(0)
              ["worker_num"]=>
              int(1)
              ["task_worker_num"]=>
              int(2)
              ["dispatch_mode"]=>
              int(5)
              ["hook_flags"]=>
              int(2147479551)
              ["enable_coroutine"]=>
              bool(true)
              ["task_enable_coroutine"]=>
              bool(true)
              ["max_wait_time"]=>
              int(15)
              ["reload_async"]=>
              bool(true)
            }
            ["connections"]=>
            object(Swoole\Connection\Iterator)#5 (0) {
            }
          }
        }
        ["master_pid"]=>
        int(29448)
        ["manager_pid"]=>
        int(29449)
        ["worker_id"]=>
        int(0)
        ["taskworker"]=>
        bool(false)
        ["worker_pid"]=>
        int(29453)
        ["stats_timer"]=>
        NULL
      }
    }
    ["type"]=>
    string(2) "->"
    ["args"]=>
    array(0) {
    }
  }
}
[2021-08-09 19:30:23 *29453.0]	ERROR	php_swoole_server_rshutdown (ERRNO 503): Fatal error: Uncaught PDOException: Cannot execute queries while other unbuffered queries are active.  Consider using PDOStatement::fetchAll().  Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute. in @swoole-src/library/core/Database/PDOProxy.php:64
Stack trace:
#0 /alidata/www/tournament/vendor/simple-swoole/db/src/BaseModel.php(1352): Swoole\Database\PDOProxy->__call()
#1 /alidata/www/tournament/vendor/simple-swoole/db/src/BaseModel.php(131): Simps\DB\BaseModel->realGetConn()
#2 /alidata/www/tournament/vendor/simple-swoole/db/src/BaseModel.php(491): Simps\DB\BaseModel->exec()
#3 /alidata/www/tournament/app/Gateway.php(104): Simps\DB\BaseModel->get()
#4 /alidata/www/tournament/app/Server.php(480): Game\App\Gateway::getPlayerData()
#5 /alidata/www/tournament/app/Server.php(319): Game\App\Server->joinGameRoom()
#6 {main}
  thrown in @swoole-src/library/core/Database/PDOProxy.php on line 64
[2021-08-09 19:30:23 $29449.0]	WARNING	check_worker_exit_status: worker#0[pid=29453] abnormal exit, status=255, signal=0
onWorkerError worker_id: 0, worker_pid: 29453, exit_code: 255, signal: 0

PDO::MYSQL_ATTR_USE_BUFFERED_QUERY=true 已开启
BaseModel 实例方法

new BaseModel([
                'host' => $config['host'],
                'port' => $config['port'],
                'database' => $config['database'],
                'username' => $config['username'],
                'password' => $config['password'],
                'charset' => $config['charset'],
                'prefix' => $config['prefix'],
                // 'unixSocket' => null,
                'options' => [
                    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
                    PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
                    PDO::ATTR_STRINGIFY_FETCHES => false,
                    PDO::ATTR_EMULATE_PREPARES => false,
                ],
                'size' => $config['pool_size'] // 连接池size
            ]);

swoole 配置

        'max_request'       =>   0, // 设置 worker 进程的最大任务数。【默认值:0 即不会退出进程】
	'worker_num'        =>   1,
        'task_worker_num'   =>   2,
        'dispatch_mode'     =>   5,
        'hook_flags'        => SWOOLE_HOOK_ALL, // 设置一键协程化 Hook 的函数范围。【默认值:不 hook】
        'enable_coroutine'  => true,
        'task_enable_coroutine' => true, // Task 开启协程
        'max_wait_time'     => 15, // 设置 Worker 进程收到停止服务通知后最大等待时间【默认值:3】
    	'reload_async'      => true, // 设置异步重启开关, 保证服务重载时,协程或异步任务能正常结束。

我排查了下,发现 quote 方法不能正确的返回,我使用了medoo2.1的 quote处理方法进行替换,发现报错次数有明显减少。
但是以上的报错问题还是存在,我想到的可能是上条查询语句 exec PDO::prepare 实际执行了但没完全返回或者报错,导致后一条语句出现上面问题。

simple-swoole/skeleton doesn't support php8

❯ composer create-project simple-swoole/skeleton todo-simps
Creating a "simple-swoole/skeleton" project at "./todo-simps"
Info from https://repo.packagist.org: #StandWithUkraine

In CreateProjectCommand.php line 435:

Could not find package simple-swoole/skeleton with stability stable in a version installable using your PHP version, PHP extensions and Composer version.

medoo 如何整合

我看了文档,说 Medoo 应该继承于 BaseModel,这样的话,我遇到的问题是,实例化他们的参数不一样,是不是还要做另外的封装

设置默认404

似乎没有提供这个功能,要实现这个功能,在不修改源码的情况下,要怎么实现呢

Super powerfull, congratulations

Ah!, my mystake, i put issue like a party, but, first is for congratulations you, is a god job, i think move to rust in two years, but with this approach i can wait more time.

Have plans for ht2 protocol ? this product have a roadmap ? What is way to contribute ?

Sorry for much question, thanks for attention.

TCP的服务没有协议呢?

如果接入tcp server,得自已定义包协议,粘包问题用swoole的package_body_offset,package_length_offset ,package_length_type 等配置自己解决吗,最好引入一下yargrpc等开源协议支持

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.