寫了一個定時任務,準備定時訪問該地址,完成匹配品牌的功能。
用了結巴分詞,分離商品標題
本地運行沒問題。在線上運行時,只查出一條商品的情況下,沒問題。多條就會自動跳到設定檔中的“ERROR_PAGE”.Log日誌檔中沒有記錄。現在不知道怎麼查看該問題的原因,找不到解決方案。
應該是循環引起的問題,但不知道問題出在哪裡?
附相關程式碼:
$quan_lists = M("Quan")->field('id,title')->where(array("fromtype" => array("gt", 0),"addtime" => array("gt", $limit_time)))->limit(20)->order("id desc")->select();
$productLogic = tkD("Product", "Logic");
$searchLogic = tkD('Search', 'Logic');
if(!empty($quan_lists)) {
foreach($quan_lists as $quan) {
//分词结果
$aTags = $productLogic->jieba($quan['title']);
if (empty($aTags)) {
continue;
}
$like_zh_map = $like_en_map = $condition = $map = array();
foreach($aTags as $tag) {
if(preg_match("/^[0-9a-zA-Z\s]+$/", $tag)) {
$like_en_map[] = "{$tag}%";
} else {
$like_zh_map[] = "{$tag}%";
}
}
if(count($like_zh_map) > 0) {
$condition['zh_name'] = array('like', $like_zh_map, 'OR');
}
if(count($like_en_map) > 0) {
$condition['en_name'] = array('like', $like_en_map, 'OR');
}
if(count($like_zh_map) > 0 && count($like_en_map) > 0) {
$condition['_logic'] = 'or';
}
$map['_complex'] = $condition;
$map['status'] = 1;
$aDatas = M('Brand')->field('id,zh_name,en_name')->where($map)->find();
if(empty($aDatas)) {
continue;
} else {
M("Quan")->where(array("id" => $quan['id']))->save(array("brand_id" => intval($aDatas["id"])));
$searchLogic->searchupdate(2, $quan['id']); //更新搜索引擎
}
}
}
public function jieba($title)
{
if (empty($title)) {
return false;
}
ini_set('memory_limit', '200M');//吃内存
import('Vendor/jieba/src/vendor/multi-array/MultiArray', '', '.php');
import('Vendor/jieba/src/vendor/multi-array/Factory/MultiArrayFactory', '', '.php');
import('Vendor/jieba/src/class/Jieba', '', '.php');
import('Vendor/jieba/src/class/Finalseg', '', '.php');
\Fukuball\Jieba\Jieba::init(array('dict' => 'small'));
\Fukuball\Jieba\Finalseg::init();
$aSeglist = \Fukuball\Jieba\Jieba::cut($title, false);
if ($aSeglist) {
$aTags = array();
foreach ($aSeglist as $str) {
if (is_numeric($str)) {
continue;
} elseif (mb_strlen($str, 'utf8') < 2) {
continue;
} else {
$aTags[] = $str;
}
}
return $aTags;
} else {
return false;
}
}
分詞的時候:
ini_set('memory_limit', '200M')
這段程式碼看起來有點問題