jdz/process
Composer 安装命令:
composer require jdz/process
包简介
Utility to debug processes calculating execution time
关键字:
README 文档
README
A PHP package for tracking the execution time of processes, sections, and subsections. This package allows you to track and format the time taken for each part of your process, providing a detailed hierarchical view of the execution time.
Features
- Track execution time of processes, sections, and subsections
- Hierarchical structure for sections and subsections
- Formatted time output
- Easy to use API
Requirements
- PHP 8.1 or higher
Installation
Install via Composer:
composer require jdz/process
Quick Start
Basic Example
Here is a basic example of how to use the Process class to track the execution time of a process, including sections and subsections. You can find the complete example in the file examples/example.php.
use JDZ\Utils\Process; $process = Process::create(); // Start the main process $process->startSection("Main Process"); // Start a subsection $process->startSubsection("Loading Data"); // Simulate loading data with a delay sleep(1); $process->endSubsection(); // Start another subsection $process->startSubsection("Processing Data"); // Simulate processing with a delay sleep(2); $process->endSubsection(); // End the main section $process->endSection(); // Get the formatted time for the entire process echo $process->getTime(); // Example output: "3 min 3 s 234 ms" // Export the sections and subsections in a hierarchical format print_r($process->toArray());
Example Output
When calling toArray(), it will return an array representing the process, sections, and subsections:
Total exec time : 3 min 3 s 234 ms ---- Main Process : 3 min 3 s 234 ms |-- Loading Data : 1 s 234 ms |-- Processing Data : 2 min 0 s 0 ms
Methods Overview
startSection(string $name): Start a new section with the given name.startSubsection(string $name, bool $endPrevious = true): Start a new subsection within the current section.endSection(): End the current section and close all its subsections.endSubsection(): End the current subsection and return to the parent section.close(): End the process and calculate the total execution time.getTime(): Get the formatted time for the entire process.toArray(): Export the sections and their execution times as an array of formatted strings.
Time Format
The time is formatted as follows:
- Minutes: Only shown if greater than 0.
- Seconds: Only shown if greater than 0 or if minutes are shown.
- Milliseconds: Always shown if non-zero, or if minutes or seconds are shown.
Examples of formatted time:
3 min 3 s 234 ms2 s 150 ms0 ms
Testing
Run the test suite:
# Run all tests composer test # Run with coverage composer test -- --coverage-html coverage # Run specific test file vendor/bin/phpunit tests/ProcessItemTest.php vendor/bin/phpunit tests/ProcessTest.php # Run with detailed output vendor/bin/phpunit --testdox
-
ProcessItemTest: 28 tests covering all aspects of the ProcessItem class, including:
- Construction and initialization
- Parent-child relationships
- Time tracking and closure
- Hierarchical export functionality
- Time formatting
-
ProcessTest: 25 tests covering all aspects of the Process class, including:
- Singleton pattern
- Section and subsection management
- Time tracking and formatting
- Complex nested workflows
- Idempotent operations
License
This library is licensed under the MIT License. See the LICENSE file for details.
Changelog
Version 2.0.0
- Removed deprecated singleton() method in favor of create() method.
- Added Unit tests
- Improved time formatting to handle zero durations correctly.
Version 1.0
- Initial release with core functionality for tracking process execution time, sections, and subsections.
jdz/process 适用场景与选型建议
jdz/process 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 01 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「debug」 「process」 「utilities」 「core」 「JDZ」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jdz/process 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jdz/process 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jdz/process 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Debug your SimpleBus EventBus and CommandBus
Doctrine implementation of the MetaborStd (Statemachine) for PHP 8.2+
nice output for debug functions for PHP 5.3
Shell command module for PHP.
Swoole server process management
A collection of enhancements and utilities for the Silverstripe UserForms module
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-01-22