Download the PHP package tomloprod/time-warden without Composer
On this page you can find all versions of the php package tomloprod/time-warden. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tomloprod/time-warden
More information about tomloprod/time-warden
Files in tomloprod/time-warden
Package time-warden
Short Description TimeWarden is a lightweight PHP library that enables you to monitor the processing time of tasks and task groups (useful during the development stage). Additionally, it allows you to set maximum execution times to tasks, empowering proactive actions when tasks exceed their planned duration.
License MIT
Informations about the package time-warden
⏱️ About TimeWarden
TimeWarden is a lightweight PHP library that allows you to monitor the processing time of tasks (useful during the development stage and debugging) and also lets you set estimated execution times for tasks, enabling reactive actions when tasks exceed their estimated duration.
TimeWarden uses high-resolution timing (hrtime) for nanosecond precision, ensuring accurate measurements even for very fast operations.
TimeWarden is framework-agnostic, meaning it's not exclusive to any particular framework. It can seamlessly integrate into any PHP application, whether they utilize frameworks like Laravel (🧡), Symfony, or operate without any framework at all.
✨ Getting Started
Reactive Actions
You can specify an estimated execution time for each task and set an action to be performed when the time is exceeded (example: send an email, add an entry to the error log, etc.).
Example
Available methods
If you're not convinced about using onExceedsMilliseconds, you have other options:
Quick Measurement
TimeWarden provides a convenient measure() method that automatically handles task creation, starting, and stopping for you. This method executes a callable and returns the execution time in milliseconds.
Example
The measure() method:
- Automatically creates a task with the provided name (or 'callable' by default)
- Starts timing before execution
- Executes your callable
- Stops timing after execution (even if an exception occurs)
- Returns the duration in milliseconds
- Integrates with groups and the TimeWarden workflow
Execution Time Debugging
It allows you to measure the execution time of tasks in your application, as well as the possibility of adding those tasks to a group.
Simple tasks
Result:
Grouped tasks
Result:
🧙 Tip
If your application has any logging system, it would be a perfect place to send the output.
Ways of using TimeWarden
You can use TimeWarden either with the aliases timeWarden() (or timewarden()):
or by directly invoking the static methods of the TimeWarden facade:
You decide how to use it 🙂
🧱 Architecture
TimeWarden is composed of several types of elements. Below are some features of each of these elements.
TimeWarden
Tomloprod\TimeWarden\Support\Facades\TimeWarden is a facade that acts as a simplified interface for using the rest of the TimeWarden elements.
Methods
Most methods in this class return their own instance, allowing fluent syntax through method chaining.
Additionally, it has all the methods of the Taskable interface.
Task
All tasks you create are instances of Tomloprod\TimeWarden\Task.
The most useful methods and properties of a task are the following:
Properties
name
Methods
Group
All groups you create are instances of the Tomloprod\TimeWarden\Group object.
The most useful methods and properties of a group are the following:
Properties
name
Methods
Additionally, it has all the methods of the Taskable interface.
Taskable
Tomloprod\TimeWarden\Contracts\Taskable is the interface used by the TimeWarden instance as well as by each task group
Methods
TimeWardenSummary
Tomloprod\TimeWarden\TimeWardenSummary is a class that allows obtaining a general summary of groups and their tasks generated with TimeWarden.
It is useful for obtaining a summary in array or string (JSON) format.
You can obtain an instance of TimeWardenSummary as follows:
Methods
Here is an example of the data returned in array format:
🚀 Installation & Requirements
Requires PHP 8.2+
You may use Composer to install TimeWarden into your PHP project:
🧑🤝🧑 Contributing
Contributions are welcome, and are accepted via pull requests. Please review these guidelines before submitting any pull requests.
TimeWarden was created by Tomás López and open-sourced under the MIT license.