承接 laracraft-tech/laravel-xhprof 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

laracraft-tech/laravel-xhprof

Composer 安装命令:

composer require laracraft-tech/laravel-xhprof

包简介

Easy XHProf setup to profile your laravel application!

README 文档

README

Logo Laravel XHProf

Total Downloads Latest Stable Version License Laravel Compatibility

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 laracraft-tech/laravel-xhprof 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 351.63k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 235
  • 点击次数: 32
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 235
  • Watchers: 2
  • Forks: 11
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-09-23