1 回答
TA贡献1963条经验 获得超6个赞
好吧,我发布的方法确实是错误的,可能会无限循环。最后,我发现解决这个问题的方法是将 microtime 函数放在最开始。我将一个新变量声明为$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");
- 1 回答
- 0 关注
- 90 浏览
添加回答
举报