我正在尝试优化我对 Cakephp 中带有分页结果的页面的查询,因此我希望使用 PHP 函数计算准确的时间microtime()。这样,我将更好地了解执行特定请求需要多少时间。
此外,我正在尝试通过 Cache::read 和 Cache::write 缓存分页结果,它们都是 Cakephp 2.x 中关于缓存方法的内部 Cakephp 函数。
因此,此时我所拥有的是:我在想,为了准确计算整个游戏中时光倒流,我应该将其余代码放在 while 循环中吗?
任何帮助将不胜感激。谢谢
$start = microtime(true);
while ($start) {
$this->paginate = $options;
$resultado = $this->paginate('Doctor');
}
$time_elapsed_secs = microtime(true) - $start;
pr($time_elapsed_secs);
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', [
'recursive' => -1,
'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;
}
神不在的星期二