zoukankan      html  css  js  c++  java
  • [PHP] Swoole整合PHP性能分析

    参考文章:Swoole整合PHP性能分析平台: Tideways+Xhgui

    根据以上文章,作为修改和补充
    本文章是这文章的补充和延伸:[Docker] 用PHP7.4+Swoole+sdebug打开PHP的二次元世界

    安装tideways扩展

    !!!FBI WARNING!!!

    git clone https://github.com/tideways/php-xhprof-extension.git
    cd php-xhprof-extension
    phpize
    ./configure --with-php-config=/usr/local/php7/bin/php-config
    make && make install

    编译完成后在php.ini中加入

    extension=tideways_xhprof.so

    查看是否安装成功

    php --ri tideways_xhprof

    成功会输出以下内容

    安装mongodb扩展

    其实非一定要依赖这个扩展的,但下面介绍的laynefyc/php-monitor扩展,会检测mongodb,所以也需要装上这个

    wget https://pecl.php.net/get/mongodb-1.7.4.tgz
    tar -zxvf mongodb-1.7.4.tgz
    cd mongodb-1.7.4
    phpize
    ./configure
    make && make install

    编译完成后在php.ini中加入

    extension=mongodb.so

    查看是否安装成功

    php --ri mongodb

    成功会输出以下内容

    安装php-monitor

    介绍: https://github.com/laynefyc/php-monitor/blob/master/README-zh_CN.md

    git clone https://github.com/laynefyc/php-monitor.git
    cd php-monitor
    composer update --ignore-platform-reqs

    注意,这里跟官方有些差异的修改。因为我们上面安装的是tideways_xhprof作性能分析的,所以它的配置需要修改一下

    src/config/config.php

    原来

    'extension' => 'tideways',

    修改为

    'extension' => 'tideways_xhprof',

    还有一个一定要注意的,官方也有提到

     就是说,你要运行这个php-monitor,就一定不能有xdebug, sdebug(swoole版的xdebug) 等等的性能分析扩展

    接着就可以让php-monitor跑在nginx下了

    nginx配置参考

    server
    {
        listen 80;
        server_name  php-monitor.ppwang.mine;
        index index.php index.html index.htm default.html default.htm default.php;
        root  /System/Volumes/Data/Software/Project/pipi/php-monitor/public;
     
        location = /favicon.ico { access_log off; log_not_found off; }
        location = /robots.txt  { access_log off; log_not_found off; }
     
        location ~ .php$ {
            # fastcgi_pass php73fpm:9730;
            fastcgi_pass php74fpmdev:9740;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            client_max_body_size 1000M;
        }
         
        access_log  /var/log/nginx/access/php-monitor.ppwang.mine.log;
        error_log  /var/log/nginx/error/php-monitor.ppwang.mine.log;
     
    }

    Laravel下代码修改

    app/Providers/EventServiceProvider.php

    public function boot()
    {
        parent::boot();
     
     
        // 其它代码
        Event::listen('laravels.received_request', function (IlluminateHttpRequest $req, $app) {
            // 这个需要根据你自己的文件所在而定的
            require '/System/Volumes/Data/Software/Project/pipi/php-monitor/src/autoPrepend.php';
        });
        Event::listen('laravels.generated_response', function (IlluminateHttpRequest $req, SymfonyComponentHttpFoundationResponse $rsp, $app) {
            pmcommonPMonitor::shutdown($req->route()->getName(), $req->request->get('remote_ip'), 'TCP');
        });
    }

    跑一次请求laravel,就可以在php-monitor看到数据了

  • 相关阅读:
    MYsql增删改查
    粘包问题
    模拟ssh远程执行命令
    Socket抽象层
    基于TCP协议的socket套接字编程
    TCP协议的三次握手和四次挥手
    大话OSI七层协议
    网络架构及其演变过程
    互联网和互联网的组成
    Windows安装MySQL
  • 原文地址:https://www.cnblogs.com/davidhhuan/p/13045633.html
Copyright © 2011-2022 走看看