用Cakephp计算分页的执行时间
我试图用Cakephp优化带有分页结果的页面查询,因此我希望使用PHP函数用Cakephp计算分页的执行时间,php,performance,cakephp,cakephp-2.1,execution-time,Php,Performance,Cakephp,Cakephp 2.1,Execution Time,我试图用Cakephp优化带有分页结果的页面查询,因此我希望使用PHP函数microtime()计算准确的时间。 这样,我将更好地了解执行特定请求需要多少时间 此外,我试图通过cache::read和cache::write来缓存分页的结果,这两个函数在cakephp2.x中都是关于缓存方法的内部Cakephp函数 因此,我在这一点上得到的是: 我在想,为了精确地计算整个时间点,我应该把其余的代码放在while循环中吗 任何帮助都将不胜感激。 谢谢 好吧,我发布的方法确实是错误的,那可能只是无限
microtime()
计算准确的时间。
这样,我将更好地了解执行特定请求需要多少时间
此外,我试图通过cache::read和cache::write来缓存分页的结果,这两个函数在cakephp2.x中都是关于缓存方法的内部Cakephp函数
因此,我在这一点上得到的是:
我在想,为了精确地计算整个时间点,我应该把其余的代码放在while循环中吗
任何帮助都将不胜感激。
谢谢
好吧,我发布的方法确实是错误的,那可能只是无限循环。最后,我发现解决这个问题的方法是将微时间函数放在一开始。我将一个新变量声明为
$time
在这之后,我只是用之前声明的时间减去实际的微时间。工作起来很有魅力
$time = microtime( TRUE );
foreach ($resultado AS $k => $r) {
$hasProduct = Cache::read(__('thedoctors::') . 'hasProduct_by_dr_' . PAIS . '_' . $r['Doctor']['id'], '1day');
if (empty($hasProduct)) {
$hasProduct = $this->DoctorsProduct->find('all', [
'fields' => ['Product.*', 'DoctorsProduct.*'],
'joins' => [
['table' => 'td_products',
'alias' => 'Product',
'type' => 'INNER',
'conditions' => [
'Product.id = DoctorsProduct.id_product'
]
],
],
'conditions' => [
'id_doctor' => $r['Doctor']['id'],
'DoctorsProduct.status' => 1
],
'order' => [
'Product.id ASC',
]
]);
Cache::write(__('thedoctors::') . 'hasProduct_by_dr_' . PAIS,
$hasProduct, '1day');
}
$resultado[$k]['Products'] = $hasProduct;
$resultado[$k]['Article'] = 0;
}
$time = microtime( TRUE ) - $time;
echo $time;
die("123");
为什么要在这里循环?这行不通,它只会无限循环,因为$start在每次检查时都是相同的正浮点值。没错,我已经尝试过了,而且内存有限。嗯,我可能会尝试另一种方法来计算执行后面的代码部分所需的时间。谢谢你的建议。
$time = microtime( TRUE );
foreach ($resultado AS $k => $r) {
$hasProduct = Cache::read(__('thedoctors::') . 'hasProduct_by_dr_' . PAIS . '_' . $r['Doctor']['id'], '1day');
if (empty($hasProduct)) {
$hasProduct = $this->DoctorsProduct->find('all', [
'fields' => ['Product.*', 'DoctorsProduct.*'],
'joins' => [
['table' => 'td_products',
'alias' => 'Product',
'type' => 'INNER',
'conditions' => [
'Product.id = DoctorsProduct.id_product'
]
],
],
'conditions' => [
'id_doctor' => $r['Doctor']['id'],
'DoctorsProduct.status' => 1
],
'order' => [
'Product.id ASC',
]
]);
Cache::write(__('thedoctors::') . 'hasProduct_by_dr_' . PAIS,
$hasProduct, '1day');
}
$resultado[$k]['Products'] = $hasProduct;
$resultado[$k]['Article'] = 0;
}
$time = microtime( TRUE ) - $time;
echo $time;
die("123");