码云推荐 | 高性能 PHP 开发框架 Agile Swoole

栏目: 编程工具 · 发布时间: 7年前

内容简介:一个高性能的PHP开发框架(swoole)需要将config/config.php中的daemonize设置为1或者true

关于Agile Swoole

一个高性能的 PHP 开发框架(swoole)

特性
    1.支持MVC
    2.支持自定义常驻进程
    3.支持多种任务模式
    4.路由自定义事件
    5.简单易用orm[可二次开发,实现接口,自动注入即可]
    6.自动协程(Coroutine,假如你的swoole是2.0以上,自动开启协程进行调度)
    7.分布式(待开发)
    8.队列(待开发)

压力测试

测试机器

双核 Intel(R) Pentium(R) CPU G2020 @ 2.90GHz
ddr3 1333mhz 4g
硬盘5400转
ubuntu 16.04 desktop

测试命令

ab -c 100 -n 50000 http://127.0.0.1:9550/

测试结果

Server Software:        swoole-http-server
Server Hostname:        127.0.0.1
Server Port:            9550

Document Path:          /
Document Length:        0 bytes

Concurrency Level:      100
Time taken for tests:   22.286 seconds
Complete requests:      50000
Failed requests:        0
Total transferred:      7350000 bytes
HTML transferred:       0 bytes
Requests per second:    2243.52 [#/sec] (mean)
Time per request:       44.573 [ms] (mean)
Time per request:       0.446 [ms] (mean, across all concurrent requests)
Transfer rate:          322.07 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.6      0      15
Processing:     0   44  32.3     44     254
Waiting:        0   44  32.3     43     248
Total:          0   45  32.3     44     254

快速开始

composer require fresh-li/agile-swoole:dev-master
cd bin
php agile.php

http://127.0.0.1:9550

路由

CONF_PATH/route.php
    [
        'path'          =>      '/',
        'dispatch'      =>      [\Controller\Welcome::class, 'index']
    ],
    [
        'path'          =>      '/sync',
        'dispatch'      =>      [\Controller\Sync::class, 'run'],
        'type'          =>      \Component\Producer\Producer::PRODUCER_SYNC
    ],
    [
        'path'          =>      '/process',
        'dispatch'      =>      [\Controller\Process::class, 'run'],
        'before'        =>      [\Controller\Process::class, 'before'],
        'after'         =>      [\Controller\Process::class, 'after'],
        'type'          =>      \Component\Producer\Producer::PRODUCER_PROCESS
    ]
    
    GET: localhost:9550
    hello world!
    
    GET: localhost:9550/sync
    sync start
    ... 10 seconds after
    sync over
    
    POST: localhost:9550/process
    this process berfore
        create process ......
    this process after

3种不同的触发模式

class Sync{
        public function index()
        {
            return 'ff';
        }
    }
    
    {"code":0,"response":"ff"}
    
    class Process{
            public function index()
            {
                return 'ff';
            }
    }
    {"code":0,"response":{"processId":"{$processId}"}}
    
    class Task{
            public function index()
            {
                return ff;
            }
    }
    {"code":0}

常驻内存任务,开启服务立马启用

$serverProcess = new ServerProcess();
    $serverProcess->addProcess(function(){
        while(true){
            //do some things
        }
    });

daemon模式測試(性能提升一倍)

需要将config/config.php中的daemonize设置为1或者true

ab -c 100 -n 50000 http://127.0.0.1:9550/
    This is ApacheBench, Version 2.3 <$Revision: 1706008 $>
    Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
    Licensed to The Apache Software Foundation, http://www.apache.org/
    
    Benchmarking 127.0.0.1 (be patient)
    Completed 5000 requests
    Completed 10000 requests
    Completed 15000 requests
    Completed 20000 requests
    Completed 25000 requests
    Completed 30000 requests
    Completed 35000 requests
    Completed 40000 requests
    Completed 45000 requests
    Completed 50000 requests
    Finished 50000 requests
    
    
    Server Software:        swoole-http-server
    Server Hostname:        127.0.0.1
    Server Port:            9550
    
    Document Path:          /
    Document Length:        38 bytes
    
    Concurrency Level:      100
    Time taken for tests:   11.934 seconds
    Complete requests:      50000
    Failed requests:        0
    Total transferred:      9300000 bytes
    HTML transferred:       1900000 bytes
    Requests per second:    4189.60 [#/sec] (mean)
    Time per request:       23.869 [ms] (mean)
    Time per request:       0.239 [ms] (mean, across all concurrent requests)
    Transfer rate:          761.00 [Kbytes/sec] received
    
    Connection Times (ms)
                  min  mean[+/-sd] median   max
    Connect:        0    0   0.4      0       8
    Processing:     0   24  55.7      6     377
    Waiting:        0   23  55.7      6     376
    Total:          0   24  55.7      6     377
    
    Percentage of the requests served within a certain time (ms)
      50%      6
      66%     10
      75%     14
      80%     17
      90%     47
      95%    162
      98%    246
      99%    288
     100%    377 (longest request)

以上所述就是小编给大家介绍的《码云推荐 | 高性能 PHP 开发框架 Agile Swoole》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

网络多人游戏架构与编程

网络多人游戏架构与编程

格雷泽 (Joshua Glazer)、马达夫 (Sanjay Madhav) / 王晓慧、张国鑫 / 人民邮电出版社 / 2017-10-1 / CNY 109.00

本书是一本深入探讨关于网络多人游戏编程的图书。 全书分为13章,从网络游戏的基本概念、互联网、伯克利套接字、对象序列化、对象复制、网络拓扑和游戏案例、延迟、抖动和可靠性、改进的延迟处理、可扩展性、安全性、真实世界的引擎、玩家服务、云托管专用服务器等方面深入介绍了网络多人游戏开发的知识,既全面又详尽地剖析了众多核心概念。 本书的多数示例基于C++编写,适合对C++有一定了解的读者阅读。本......一起来看看 《网络多人游戏架构与编程》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具