Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Snapshot Profiler Xhprof Laravel Package

aeatech/snapshot-profiler-xhprof

View on GitHub
Deep Wiki
Context7

AEATech - Snapshot profiler xhprof

Code Coverage

The package contains implementation of aeatech/snapshot-profiler-contracts to profile applications with xhprof. It can be used for production profiling.

System requirements:

Installation (Composer):

composer require aeatech/snapshot-profiler-xhprof

Quick start

<?php
declare(strict_types=1);

use AEATech\SnapshotProfiler\Profiler;
use AEATech\SnapshotProfilerXhprof\Adapter;
use AEATech\SnapshotProfilerXhprof\Saver;
use Xhgui\Profiler\Profiler as BackendProfiler;
use Xhgui\Profiler\ProfilingFlags;

require_once 'vendor/autoload.php';

/**
 * Start initialization
 */
$profilerConfig = [
    'profiler' => BackendProfiler::PROFILER_XHPROF,
    'profiler.flags' => [
        ProfilingFlags::MEMORY,
    ],
    'save.handler' => BackendProfiler::SAVER_UPLOAD,
    'save.handler.upload' => [
        'uri' => 'http://xhgui:80/run/import',
        'timeout' => 1,
    ],
];
$backendProfiler = new BackendProfiler($profilerConfig);

$saver = new Saver($backendProfiler);

$adapterIniSettings = [
    'xhprof.collect_additional_info' => '1',
];
$adapter = new Adapter($backendProfiler, $adapterIniSettings);
$profiler = new Profiler($adapter);

$profilingOptions = [];
/**
 * End initialization
 */

/**
 * Start profiling
 */

$profiler->enable();
/**
 * It's doing nothing and added for backward compatibility with newrelic
 */
$profiler->setProfilingOptions($profilingOptions);

for ($i = 0; $i < 10; $i++) {
    random_int(1, 10);
}

$data = $profiler->disable();
/**
 * End profiling
 */

/**
 * Start customization (not necessarily)
 */

/**
 * If you use fpm it will take current URL as snapshot name
 * If you use cli it will take script.php as snapshot name
 * Example of custom snapshot name
 */
$data[Adapter::KEY_META][Adapter::KEY_META_URL] = '1.0.0|serviceName|env|snapshotName';

/**
 * Set snapshot timestamps (usable for cli processes)
 */
$dateTime = new DateTime();
$timestamp = $dateTime->getTimestamp();
$data[Adapter::KEY_META][Adapter::KEY_META_REQUEST_TS_MICRO] = [
    Adapter::KEY_META_REQUEST_TS_MICRO_SEC => $timestamp,
    Adapter::KEY_META_REQUEST_TS_MICRO_USEC => $dateTime->format('u'),
];
$data[Adapter::KEY_META][Adapter::KEY_META_SERVER][Adapter::KEY_META_SERVER_REQUEST_TIME]
    = $timestamp;
$data[Adapter::KEY_META][Adapter::KEY_META_SERVER][Adapter::KEY_META_SERVER_REQUEST_TIME_FLOAT]
    = $dateTime->format('U.u');
/**
 * End customization
 */

/**
 * Save profiling result
 */
$saver->save($data);

/**
 * http://127.0.0.1:8142 - profile results here
 */

License

MIT License. See LICENSE for details.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity