File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ use Xhgui \Profiler \Exception \ProfilerException ;
4+ use Xhgui \Profiler \Profiler ;
5+
6+ /**
7+ * Plugin to capture profiling data using for XHGui.
8+ *
9+ * @author Elan Ruusamäe <glen@delfi.ee>
10+ *
11+ * Example:
12+ * $config = new Zend_Config(array(
13+ * // ...
14+ * ));
15+ * $controller->registerPlugin(new XhguiProfilerPlugin($config), 150);
16+ */
17+ class XhguiProfilerPlugin extends Zend_Controller_Plugin_Abstract
18+ {
19+ /** @var Zend_Config */
20+ private $ config ;
21+
22+ /** @var Profiler */
23+ private $ profiler ;
24+
25+ public function __construct ($ config )
26+ {
27+ $ this ->config = $ config ;
28+ }
29+
30+ public function preDispatch (Zend_Controller_Request_Abstract $ request )
31+ {
32+ $ this ->startProfiler ();
33+ }
34+
35+ public function postDispatch (Zend_Controller_Request_Abstract $ request )
36+ {
37+ }
38+
39+ private function startProfiler ()
40+ {
41+ try {
42+ $ this ->getProfiler ()->start ();
43+ } catch (ProfilerException $ e ) {
44+ error_log ('Profiler error: ' . $ e ->getMessage ());
45+ }
46+ }
47+
48+ /**
49+ * @return Profiler
50+ */
51+ private function getProfiler ()
52+ {
53+ if ($ this ->profiler !== null ) {
54+ return $ this ->profiler ;
55+ }
56+
57+ return $ this ->profiler = new Profiler ($ this ->config ->toArray ());
58+ }
59+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ use Xhgui \Profiler \Profiler ;
4+
5+ function register_xhgui_plugin (Zend_Controller_Front $ controller )
6+ {
7+ $ config = new Zend_Config (array (
8+ /**
9+ * Determine whether the profiler should run.
10+ * This default implementation just disables the profiler.
11+ * Override this with your custom logic in your config
12+ * @return bool
13+ */
14+ 'profiler.enable ' => function () {
15+ return true ;
16+ },
17+
18+ // Saver to use.
19+ // Please note that 'pdo' and 'mongo' savers are deprecated
20+ // Prefer 'upload' or 'file' saver.
21+ 'save.handler ' => Profiler::SAVER_UPLOAD ,
22+
23+ // Saving profile data by upload is only recommended with HTTPS
24+ // endpoints that have IP whitelists applied.
25+ // https://github.com/perftools/php-profiler#upload-saver
26+ 'save.handler.upload ' => array (
27+ 'url ' => 'https://example.com/run/import ' ,
28+ // The timeout option is in seconds and defaults to 3 if unspecified.
29+ 'timeout ' => 3 ,
30+ // the token must match 'upload.token' config in XHGui
31+ 'token ' => 'token ' ,
32+ ),
33+ ));
34+
35+ $ controller ->registerPlugin (new XhguiProfilerPlugin ($ config ), 150 );
36+ }
You can’t perform that action at this time.
0 commit comments