Download the PHP package rotexsoft/callable-execution-timer without Composer

On this page you can find all versions of the php package rotexsoft/callable-execution-timer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package callable-execution-timer

Callable Execution Timer

Run PHP Tests and Code Quality Tools   Release   License   Coverage Status   GitHub repo size   Packagist Downloads GitHub top language   Packagist PHP Version Support   GitHub commits since latest release (by date)   GitHub last commit   GitHub Release Date  

Libraries.io dependency status for GitHub repo

A simple PHP library for tracking the total amount of time a callable (e.g. function / method) takes to execute (it can also return the result of executing the callable, if desired).

If you want to do some simple execution time profiling in your application, without using some full blown tool like debugbar or xdebug, then this is the package for you.

Installation

Via composer: (Requires PHP 7.4+ or PHP 8.0+).

composer require rotexsoft/callable-execution-timer

Branching

These are the branches in this repository:

Introduction

A simple PHP library for tracking the total amount of time a callable (e.g. function / method) takes to execute and return result(s) (if any).

For the rest of this documentation the term callable will mostly be referring to functions / methods

This library also provides information associated with each execution / invocation of the callable such as:

Executing callables

Executing built-in php functions

Let's call php's built-in strtolower & strtoupper functions:

NOTE: The first argument passed to CallableExecutionTimer::callFunc(...) is a name (conforming to PHP's method naming convention) you want to name the callable you are about to execute. This name will be used to label the information related to the execution of the callable as will be shown later on in this documentation.

NOTE: The second argument passed to CallableExecutionTimer::callFunc(...) is the callable you are trying to execute.

NOTE: The third argument passed to CallableExecutionTimer::callFunc(...) is an array containing all the arguments to be passed to the callable you are trying to execute. You can omit this argument if the callable to be executed does not accept any arguments.

Executing user defined functions

Executing class methods

Executing parent and child class methods

Executing namespaced static class methods

Executing lambda / anonymous functions

Executing an object that is an instance of a class that has an __invoke method

You can also use instances of \FunctionExecutionTimer\CallableExecutionTimer to execute callables like below:

WARNING: Executing a callable that has one or more parameters that should be passed by reference should be done using \FunctionExecutionTimer\CallableExecutionTimer::callFunc(...) or executing the function by using the __invoke(array $args) mechanism on the instance of \FunctionExecutionTimer\CallableExecutionTimer the callable is bound to.

It won't work by trying to invoke the callable on an instance of \FunctionExecutionTimer\CallableExecutionTimer using the method call syntax that triggers __call() under the hood.

For example, you can execute the lambda function below that accepts an argument by reference via the following two ways:

Retrieving execution statistics

There are two ways to retrieve information associated with each execution of callables performed via this library:

  1. You can call the getLatestBenchmark() method on an instance of \FunctionExecutionTimer\CallableExecutionTimer which you just used to execute a callable to get information about the most recent callable execution via that object. This method returns an array with the following keys (in bold, not including the colon):

    • function : A string. The name (conforming to PHP's method naming convention) you labeled the callable you executed
    • args : An array. Contains the arguments you passed to the callable you executed, if any, otherwise it would be an empty array.
    • start_time : A float or an Integer. The timestamp in nanoseconds when the execution of the callable started.
    • end_time : A float or an Integer. The timestamp in nanoseconds when the execution of the callable ended.
    • total_execution_time_in_seconds : A float or an Integer. The total number of seconds it took to execute the callable.
    • return_value : The value returned from the callable that was executed, if any, else NULL.
    • file_called_from : A string. The absolute path to the file from which the callable was executed.
    • line_called_from : An Integer. The exact line number in the file from which the callable was executed.

    Below is an example:

    The code above will generate output like the one below:

  2. You can call \FunctionExecutionTimer\CallableExecutionTimer::getBenchmarks() to get information about the all callable executions performed via

    • all calls to \FunctionExecutionTimer\CallableExecutionTimer::callFunc(...)
    • and all callable executions via various instances of \FunctionExecutionTimer\CallableExecutionTimer

    This method returns an array of arrays. Each sub-array has the structure of the array returned by the getLatestBenchmark() method described above. Below is some sample code:

    The code above will generate output like the one below:

IT IS RECOMMENDED THAT YOU CALL \FunctionExecutionTimer\CallableExecutionTimer::clearBenchmarks() BEFORE YOU START EXECUTING THE CALLABLES THAT YOU WANT TO GET EXECUTION INFORMATION FOR. THIS WILL CLEAR ALL PREVIOUS EXECUTION INFO FROM PRIOR CALLABLE EXECUTIONS.


All versions of callable-execution-timer with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package rotexsoft/callable-execution-timer contains the following files

Loading the files please wait ....