1 回答

TA貢獻1963條經驗 獲得超6個贊
好吧,我發(fā)布的方法確實是錯誤的,可能會無限循環(huán)。最后,我發(fā)現(xiàn)解決這個問題的方法是將 microtime 函數(shù)放在最開始。我將一個新變量聲明為$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 關注
- 115 瀏覽
添加回答
舉報