定制 razra/stopwatch 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

razra/stopwatch

Composer 安装命令:

composer require razra/stopwatch

包简介

PHP Stopwatch

README 文档

README

Build Status License

Installation

composer require "razra/stopwatch: ^1"

How to use

  1. You can define stopwatch in 2 ways

    First:

    $stopwatch = new Stopwatch('someName');

    Second:

    $stopwatch = Stopwatch::start('someName');
    // or without parameter (that stopwatch will try to get name of method where its called)
    $stopwatch = Stopwatch::start();
  2. Stop the stopwatch

    $stopwatch->stop();
  3. Generate html report

    // it will create html page with report of stopwatches in given path
    $reporter = new HtmlReported('path/to/your/folder');
    $reporter->report();

Availability to create custom reporter

You can always create you report if you want. You can get all executed stopwatches from StopwatchCollection::getAll(), it will return array of Stopwatch objects all execute stopwatches.

Example structure:

    [
        'sectionName' => [
            new Stopwatch(),
            new Stopwatch(),
            new Stopwatch(),
            ...
        ],
        'anotherSectionName' => [
            new Stopwatch(),
            new Stopwatch(),
            new Stopwatch(),
            ...
        ],
        ...
    ]

Usage example:

<?php

require_once __DIR__ . '/vendor/autoload.php';

use Razra\Component\Stopwatch\HtmlReported;
use Razra\Component\Stopwatch\Stopwatch;

// start our first stopwatch
$stopwatch = Stopwatch::start('Application');

class StopwatchExample
{
    public function first()
    {
        // start our second stopwatch
        $stopwatch = Stopwatch::start();

        for ($i =0; $i < 100000000; $i++) {
        }

        // stop second stopwatch and reset
        $stopwatch->stop()->reset();

        // do something...
        
        // stop second stopwatch and reset
        // it will have time difference between prev reset and this stop
        $stopwatch->stop()->reset();

        // do something
        
        // stop second stopwatch
        $stopwatch->stop();
    }

    public function second()
    {
        // start our third stopwatch
        $stopwatch = Stopwatch::start();

        // stop third stopwatch
        $stopwatch->stop();
    }

    public function third()
    {
        // start our fourth stopwatch
        $stopwatch = Stopwatch::start();

        // stop fourth stopwatch
        $stopwatch->stop();
    }
}

// call methods
$stopwatchExample = new StopwatchExample();
$stopwatchExample->first();
$stopwatchExample->second();
$stopwatchExample->third();

$pathForReports = __DIR__ . '/reported';

if (! is_dir($pathForReports)) {
    mkdir($pathForReports);
}

// stop our first stopwatch
$stopwatch->stop();

// report our stopwatches, will put html page in $pathForReports path
$reporter = new HtmlReported($pathForReports);
$reporter->report();

统计信息

  • 总下载量: 9
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-02-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固