PHP code example of ayesh / php-timer

1. Go to this page and download the library: Download ayesh/php-timer 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/ */

    

ayesh / php-timer example snippets


    
    use Ayesh\PHP_Timer\Timer;
    Timer::start();

    Timer::start('something');

    Timer::start(__FUNCTION__);

    Timer::read(); // Default timer.
    Timer::read('default'); // Default timer.
    Timer::read('something'); // Timer started with key "something".

    Timer::read('something', Timer::FORMAT_PRECISE); // 0.10180473327637

    Timer::stop(); // Default timer.
    Timer::stop('something'); // Timer started with key "something"

    Timer::reset(); // Default timer.
    Timer::reset('something');
    Timer::resetAll(); // Resets all timers.

    
    use Ayesh\PHP_Timer\Timer;

    Timer::start();
    // do your processing here.
    $time = Timer::read('default', Timer::FORMAT_SECONDS);
    echo "Script took {$time} second(s)";

    
    use Ayesh\PHP_Timer\Timer;

    Timer::start('full');

    Timer::start('laps');
    sleep(1);
    Timer::stop('laps');

    sleep(2); // This time is not calculated under 'laps'

    Timer::start('laps');
    sleep(1);
    Timer::stop('laps');

    echo Timer::read('full', Timer::FORMAT_SECONDS); // 4 seconds.
    echo "<br />";
    echo Timer::read('laps', Timer::FORMAT_SECONDS); // 2 seconds (1 + 1)
bash
    composer