laracraft-tech/laravel-xhprof
Composer 安装命令:
composer require laracraft-tech/laravel-xhprof
包简介
Easy XHProf setup to profile your laravel application!
README 文档
README
Introduction
Laravel XHProf gives you a simple way to profile your Laravel application using the well-known XHProf PHP extension, originally developed by Facebook. It also walks you through setting up the XHProf UI, which lets you visualize, save, and analyze your profiling results.
Installation
First, you'll need to install the PHP extension. We highly recommend using Ondrej's PPA, since it's well maintained and covers pretty much every PHP version.
Native PHP environment
If you're running PHP natively on your system, just install the XHProf extension:
sudo add-apt-repository ppa:ondrej/php sudo apt-get update sudo apt-get install php php-xhprof Graphviz # Verify the extension is loaded php -i | grep xhprof # you might need to restart your webserver or php-fpm afterwards
Note: Graphviz is required to generate callgraphs.
Laravel Sail environment
If you're using Laravel Sail, here's how to set things up:
sail up -d sail artisan sail:publish # Check docker-compose.yml to see which PHP version is used under build->context (e.g. ./docker/8.1) # Then open the matching Dockerfile: nano docker/<php-version>/Dockerfile # Find the block where all PHP extensions get installed and add "php<php-version>-xhprof graphviz \" # Now rebuild Sail sail down ; sail build --no-cache ; sail up -d # this may take a while... # Verify the extension is loaded sail php -i | grep xhprof
Note: The provided Laravel Sail Dockerfile already uses Ondrej's PPA.
Install the Package
composer require laracraft-tech/laravel-xhprof --dev php artisan vendor:publish --provider="LaracraftTech\LaravelXhprof\XHProfServiceProvider" --tag="config"
Install the UI
We use the fork by "preinheimer", which is the one recommended in the official PHP docs: https://www.php.net/manual/en/xhprof.requirements.php
mkdir public/vendor ; git clone git@github.com:preinheimer/xhprof.git ./public/vendor/xhprof # If you haven't already, we recommend adding public/vendor to your .gitignore echo "/public/vendor" >> .gitignore
Database
The UI package stores and reads its profiling data from a table that is hard coded to details.
If you already have a table with that name in your database, you'll need to take a few extra steps.
Otherwise, here's the straightforward path:
If you don't already have a details table in your database:
php artisan vendor:publish --provider="LaracraftTech\LaravelXhprof\XHProfServiceProvider" --tag="migrations" php artisan migrate
If you already have a details table in your database:
In this case we recommend using a separate database just for XHProf.
CREATE DATABASE xhprof; USE xhprof; CREATE TABLE IF NOT EXISTS `details` ( `id` char(64) COLLATE utf8mb4_unicode_ci NOT NULL, `url` char(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `c_url` char(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `server name` char(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `perfdata` longblob, `type` tinyint DEFAULT NULL, `cookie` longblob, `post` longblob, `get` blob, `pmu` int DEFAULT NULL, `wt` int DEFAULT NULL, `cpu` int DEFAULT NULL, `server_id` char(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `aggregateCalls_include` char(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`), KEY `details_url_index` (`url`), KEY `details_c_url_index` (`c_url`), KEY `details_cpu_index` (`cpu`), KEY `details_wt_index` (`wt`), KEY `details_pmu_index` (`pmu`), KEY `details_timestamp_index` (`timestamp`), KEY `details_server name_timestamp_index` (`server name`,`timestamp`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
Note: don't forget to create a user that has privileges on the new database!
Config
Now let's configure a few settings:
cp public/vendor/xhprof/xhprof_lib/config.sample.php public/vendor/xhprof/xhprof_lib/config.php # 1. Adjust the DB credentials to match your setup # 2. Enable the dot_binary section # 3. If you're working locally, set $controlIPs to false nano public/vendor/xhprof/xhprof_lib/config.php
Usage
Just set XHPROF_ENABLED=true in your .env file,
and from now on every request to your application will be profiled.
Visit <your-host>/vendor/xhprof/xhprof_html/ to view the results.
Happy analyzing!
Security
If you discover any security-related issues, please email zacharias.creutznacher@gmail.com instead of using the issue tracker.
Credits
License
MIT. Please see the license file for more information.
laracraft-tech/laravel-xhprof 适用场景与选型建议
laracraft-tech/laravel-xhprof 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 351.63k 次下载、GitHub Stars 达 235, 最近一次更新时间为 2022 年 09 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「profiler」 「profiling」 「xhprof」 「laravel」 「profile」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 laracraft-tech/laravel-xhprof 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 laracraft-tech/laravel-xhprof 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 laracraft-tech/laravel-xhprof 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Quick profiling of your code for Laravel
g4 application profiler package
Excimetry PHP package. Bridge between ext-eximer and open telemetry
An SDK for sending profiling data to Perfbase
MongoQP is a frontend for MongoDB's query profiler collection.
PHPUnit loggers to profile tests.
统计信息
- 总下载量: 351.63k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 235
- 点击次数: 32
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-09-23