8000 Example: Add XhguiProfilerPlugin for zend framework v1 by glensc · Pull Request #90 · perftools/php-profiler · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Example: Add XhguiProfilerPlugin for zend framework v1 #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions contrib/zf1/XhguiProfilerPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

use Xhgui\Profiler\Exception\ProfilerException;
use Xhgui\Profiler\Profiler;

/**
* Plugin to capture profiling data using for XHGui.
*
* @author Elan Ruusamäe <glen@delfi.ee>
*
* Example:
* $config = new Zend_Config(array(
* // ...
* ));
* $controller->registerPlugin(new XhguiProfilerPlugin($config), 150);
*/
class XhguiProfilerPlugin extends Zend_Controller_Plugin_Abstract
{
/** @var Zend_Config */
private $config;

/** @var Profiler */
private $profiler;

public function __construct($config)
{
$this->config = $config;
}

public function preDispatch(Zend_Controller_Request_Abstract $request)
{
$this->startProfiler();
}

public function postDispatch(Zend_Controller_Request_Abstract $request)
{
}

private function startProfiler()
{
try {
$this->getProfiler()->start();
} catch (ProfilerException $e) {
error_log('Profiler error: ' . $e->getMessage());
}
}

/**
* @return Profiler
*/
private function getProfiler()
{
if ($this->profiler !== null) {
return $this->profiler;
}

return $this->profiler = new Profiler($this->config->toArray());
}
}
36 changes: 36 additions & 0 deletions examples/zf1-plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use Xhgui\Profiler\Profiler;

function register_xhgui_plugin(Zend_Controller_Front $controller)
{
$config = new Zend_Config(array(
/**
* Determine whether the profiler should run.
* This default implementation just disables the profiler.
* Override this with your custom logic in your config
* @return bool
*/
'profiler.enable' => function () {
return true;
},

// Saver to use.
// Please note that 'pdo' and 'mongo' savers are deprecated
// Prefer 'upload' or 'file' saver.
'save.handler' => Profiler::SAVER_UPLOAD,

// Saving profile data by upload is only recommended with HTTPS
// endpoints that have IP whitelists applied.
// https://github.com/perftools/php-profiler#upload-saver
'save.handler.upload' => array(
'url' => 'https://example.com/run/import',
// The timeout option is in seconds and defaults to 3 if unspecified.
'timeout' => 3,
// the token must match 'upload.token' config in XHGui
'token' => 'token',
),
));

$controller->registerPlugin(new XhguiProfilerPlugin($config), 150);
}
Loading
0