Magento 2开发教程
来源:互联网 发布:贵州伟东云上大数据 编辑:程序博客网 时间:2024/06/09 23:51
关于数据库分析器(profiler)
Magento数据库分析器显示页面上执行的所有查询,包括每个查询的时间和什么样的参数被执行。
1: 修改部署配置
修改<Magento 2 安装目录>/app/etc/env.php
将下列代码添加到 magento2/blob/2.0/lib/internal/Magento/Framework/DB/Profiler.php:
'profiler' => [ 'class' => '\Magento\Framework\DB\Profiler', 'enabled' => true, ],
示例如下:
'db' => array ( 'table_prefix' => '', 'connection' => array ( 'default' => array ( 'host' => 'localhost', 'dbname' => 'magento', 'username' => 'magento', 'password' => 'magento', 'model' => 'mysql4', 'engine' => 'innodb', 'initStatements' => 'SET NAMES utf8;', 'active' => '1', 'profiler' => [ 'class' => '\Magento\Framework\DB\Profiler', 'enabled' => true, ], ), ), ),
2: 配置输出
/** @var \Magento\Framework\App\ResourceConnection $res */$res = \Magento\Framework\AppObjectManager::getInstance()->get('Magento\Framework\App\ResourceConnection');/** @var Magento\Framework\DB\Profiler $profiler */$profiler = $res->getConnection('read')->getProfiler();echo "<table cellpadding='0' cellspacing='0' border='1'>";echo "<tr>";echo "<th>Time <br/>[Total Time: ".$profiler->getTotalElapsedSecs()." secs]</th>";echo "<th>SQL [Total: ".$profiler->getTotalNumQueries()." queries]</th>";echo "<th>Query Params</th>";echo "</tr>";foreach ($profiler->getQueryProfiles() as $query) { /** @var Zend_Db_Profiler_Query $query*/ echo '<tr>'; echo '<td>', number_format(1000 * $query->getElapsedSecs(), 2), 'ms', '</td>'; echo '<td>', $query->getQuery(), '</td>'; echo '<td>', json_encode($query->getQueryParams()), '</td>'; echo '</tr>';}echo "</table>";
3: 查看输出结果
访问magento 2 的任何页面,示例结果如下图:
阅读全文
0 0
- Magento 2开发教程
- Magento 2开发教程
- magento开发教程-Magento 2支付提供商网关
- Magento模块开发教程
- Magento-中文开发教程
- Magento开发手册教程
- Magento开发教程
- magento开发教程
- Magento开发教程
- magento widget开发使用教程
- Magento开发教程 - 修改magento默认订单发票(invoice)
- magento 开发笔记2
- Magento 2中文文档教程
- Magento 2中文手册教程
- Magento 2中文手册教程
- Magento 2中文手册教程
- Magento 2中文手册教程
- Magento 2中文手册教程
- Lowest Common Multiple Plus(GCD+GBD)
- 人脸抠图
- JavaWeb分页(前端+后台)(后台部分)
- 标准文件IO
- 《如何阅读一本书》
- Magento 2开发教程
- 配所有的特殊符号
- 循环:数字特征值
- [noip 2012] 换教室(线段树)
- 综合实践——银行储蓄系统
- Moving Averages(1): Introduction
- Java基础——注解(Annotation)
- Hibernate逆向代码问题
- c++ 用socket实现TCPIP通信