xhprof 不适用于 php rabbitmq 消费者
xhprof not working for php rabbitmq consumers
我有使用 symfony2-framework 在 php 中编写的 rabbitmq 消费者,我正在尝试使用 xhprof 查看系统的内部工作和问题。问题是它没有将任何内容保存到 mongodb 中。 Mongo完全是空的。
我尝试在 php.ini、应用程序 .htaccess 文件和 apaches 虚拟主机中设置 auto_prepend_file(添加必要的头文件)。
我将分析器设置为分析每个请求,它分析其他一切都很好,eeexcept the rabbitmq-consumers 运行 在后台。但为什么不呢?
例如,我调用了 phpinfo.php -file,它完美地描述了它,但不是消费者,不。
Xhprof 在脚本存在时对数据进行分析,这对 rabbitmq 消费者来说从来都不是,因为它们是后台进程 运行。
所以:一种解决方案是将头文件中的适当开始和退出代码添加到 运行 的脚本中,但这对我来说太麻烦了。
Xhprof 不会在脚本退出时强制保存配置文件数据。但是 当 你指示他这样做时。许多设置包括来自 https://github.com/patrickallaert/xhprof#profile-your-page 的东西,使用 register_shutdown_function()
,它在脚本结束时执行。
但是您可以在要分析的代码周围放置 xhprof_enable()
/ xhprof_disable()
。在循环中也是完全有效的,例子:
<?php
while (true) {
// Fetch a message from the queue
// Start profiling
xhprof_enable();
// [treatment of your message]
// End profiling and dump the result
file_put_contents("/tmp/" . uniqid() . ".your_app.xhprof", serialize(xhprof_disable()));
}
我有使用 symfony2-framework 在 php 中编写的 rabbitmq 消费者,我正在尝试使用 xhprof 查看系统的内部工作和问题。问题是它没有将任何内容保存到 mongodb 中。 Mongo完全是空的。
我尝试在 php.ini、应用程序 .htaccess 文件和 apaches 虚拟主机中设置 auto_prepend_file(添加必要的头文件)。
我将分析器设置为分析每个请求,它分析其他一切都很好,eeexcept the rabbitmq-consumers 运行 在后台。但为什么不呢?
例如,我调用了 phpinfo.php -file,它完美地描述了它,但不是消费者,不。
Xhprof 在脚本存在时对数据进行分析,这对 rabbitmq 消费者来说从来都不是,因为它们是后台进程 运行。
所以:一种解决方案是将头文件中的适当开始和退出代码添加到 运行 的脚本中,但这对我来说太麻烦了。
Xhprof 不会在脚本退出时强制保存配置文件数据。但是 当 你指示他这样做时。许多设置包括来自 https://github.com/patrickallaert/xhprof#profile-your-page 的东西,使用 register_shutdown_function()
,它在脚本结束时执行。
但是您可以在要分析的代码周围放置 xhprof_enable()
/ xhprof_disable()
。在循环中也是完全有效的,例子:
<?php
while (true) {
// Fetch a message from the queue
// Start profiling
xhprof_enable();
// [treatment of your message]
// End profiling and dump the result
file_put_contents("/tmp/" . uniqid() . ".your_app.xhprof", serialize(xhprof_disable()));
}