php循环处理中,中间有个方法执行错误有时会中断循环,我们可以使用php的异常处理配合日志来解决:
foreach ($full_list as $key => $fullData) {
try {
// 更新单品信息缓存
try {
self::setProductCache($fullData, 0);
} catch (Exception $e) {
logs(['code'=>$e->getCode(),'msg'=>$e->getMessage(),'fid'=>$fullData['fid']],'up_one_product_detail_cache');
}
// 格式化数据
try {
StoreFullModel::setFullFormat($fullData, 0);
} catch (Exception $e) {
logs(['code'=>$e->getCode(),'msg'=>$e->getMessage(),'fid'=>$fullData['fid']],'up_one_product_detail_cache');
}
// 更新搭配秀缓存
try {
$circle = new CircleService();
$circle->getFullCircleImage($fullData['fid'], 1, 15, 0);
} catch (Exception $e) {
logs(['code'=>$e->getCode(),'msg'=>$e->getMessage(),'fid'=>$fullData['fid']],'up_one_product_detail_cache');
}
$success_num++;
} catch (Exception $e) {
$error_num++;
logs(['code'=>$e->getCode(),'msg'=>$e->getMessage(),'fid'=>$fullData['fid']],'up_cache_all_error');
}
}