PHP code example of extraswoft / tideways

1. Go to this page and download the library: Download extraswoft/tideways library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

extraswoft / tideways example snippets


   [mongodb]
   extension=mongodb.so
   [tideways]
   extension=tideways.so
   ;不需要自动加载,在程序中控制就行
   tideways.auto_prepend_library=0
   ;频率设置为100,在程序调用时能改
   tideways.sample_rate=100

   git clone https://github.com/laynefyc/xhgui-branch.git
   cd xhgui-branch
   php install.php

    $ mongo
    > use xhprof
    > db.results.ensureIndex( { 'meta.SERVER.REQUEST_TIME' : -1 } )
    > db.results.ensureIndex( { 'profile.main().wt' : -1 } )
    > db.results.ensureIndex( { 'profile.main().mu' : -1 } )
    > db.results.ensureIndex( { 'profile.main().cpu' : -1 } )
    > db.results.ensureIndex( { 'meta.url' : 1 } )

    server {
        listen       80;
        server_name  local-xhgui.xxxx.com;
        root  /apps/webroot/production/xhgui-branch/webroot;
    
        location / {
            index  index.php;
            if (!-e $request_filename) {
                rewrite . /index.php last;
            }
        }
    
        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9001;
            fastcgi_index  index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            

    composer 

    
    use ExtraSwoft\Tideways\Middleware\TidewaysMiddleware;
    
    return [
        'ExtraSwoft\\Tideways\\Middleware\\TidewaysMiddleware' => [
            'class' => TidewaysMiddleware::class,
            'root' => '${config.tideways.root}',
            'start' => '${config.tideways.start}',
            'host' => '${config.tideways.host}',
            'db' => '${config.tideways.db}',
        ]
    ];

   'tideways' => [
           'root' => env('TIDEWAYS_ROOT'),
           'start' => env('TIDEWAYS_START'),
           'host' => env('TIDEWAYS_DB_HOST'),
           'db' => env('TIDEWAYS_DB_DB'),
       ] 

    #tideways
    TIDEWAYS_ROOT=/apps/webroot/production/xhgui-branch
    TIDEWAYS_START=true
    TIDEWAYS_DB_HOST=mongodb://127.0.0.1:27017
    TIDEWAYS_DB_DB=xhprof

'profiler.enable' => function() {
    // url 中包含debug=1则百分百捕获
    if(!empty($_GET['debug'])){
        return True;
    }else{
        // 1%采样
        return rand(1, 100) === 42;
    }
}

return rand(1, 100) === 42; 
为1%的采样率,改成return True;则标识每次都采样