周 泽泽 Fri Jul 19 04:22:34 -0400 2013

Subject: PHP Fatal error: Out of memory (allocated -1185677312) (tried to allocate 79 bytes) in /home/frdc/zhouence/CgmCloudTest/DBActive/lib/Model.php on line 460

who can tell me "what's the problem",my code as belowing

require_once '../Web/Init.php';
define ( 'SIMILARITY_THRESHOLD', '0.55' );

while(true){
$options = null;
$options['conditions'] = 'processOrNot = 0';
$options['limit'] = 20;
$results = KeywordInfo::find('all',$options);
if(count($results)){
//处理每一条未处理信息
foreach($results as $row_keywordinfo){
//获取每条信息的所属信息
$row_info = $row_keywordinfo->info;
$infoId = $row_info->id;
$keywords_1 = explode(" ",$row_info->keywords);
$date = $row_info->date;
//依据关键字id获取该未处理信息所属主题的主题id
$row_keyword = $row_keywordinfo->keyword;
$topicId = $row_keyword->topic_id;
//判断event_details表中该$infoId对应的所有的topic_id是否包含$topicId,如果包含,则不更新到event_details表中
$mark = false;
$options = null;
$options['conditions'] = 'info_id = '.$infoId;
$row_eventdetails = EventDetail::find('all',$options);
if(count($row_eventdetails)){
foreach($row_eventdetails as $row_eventdetail){
$topic = $row_eventdetail->event->topic;
if($topicId == $topic->id){
$mark = true;
}
}
}
if($mark){//该主题下已经包含该信息
// 信息处理完毕,则修改该信息的processOrNot的值为1
$row_keywordinfo->processornot = 1;
$row_keywordinfo->save();
continue;
}
//依据topicId从events表中查询该主题最近一个月有无事件
$date = $row_info->date;
$start_date = date ( "Y-m-d", strtotime ( $date ) - 15 * 24 * 60 * 60 );
$end_date = date ( "Y-m-d", strtotime ( $date ) + 15 * 24 * 60 * 60 );
$options['conditions'] = 'topic_id = '.$topicId.' and end_date >=\''.$start_date.'\''.' and end_date <=\''.$end_date.'\'';
$count_events = Event::count($options);

$maxThreshold = 0;
$similar_EventId = null;
$similar_info = null;
if($count_events != 0){//该主题下已有事件数目不为0,则与已有事件下的信息一一进行相似度比较
for($i=0;;$i=$i+20){
$options = null;
$options['conditions'] = 'topic_id = '.$topicId.' and end_date >=\''.$start_date.'\''.' and end_date <=\''.$end_date.'\'';;
$options['limit'] = 20;
$options['offset'] = $i;
$options['include'] = array('event_details');
$results_events = Event::find('all',$options);
if(count($results_events)){
foreach($results_events as $row_event){
foreach($row_event->event_details as $row_eventdetail){
$row_info_1 = $row_eventdetail->info;
$keywords_2 = explode(" ",$row_info_1->keywords);
$similarity = Utils::jaccardSimilarity ( $keywords_1, $keywords_2 );
if ($similarity > $maxThreshold) {
$maxThreshold = $similarity;
$similar_EventId = $row_eventdetail->event_id;
$similar_info = $row_info;
}
}
}
}else{
break;
}
}
}
if ($maxThreshold > SIMILARITY_THRESHOLD) { // 为某事件增添信息
inseratNewInfoForEventInfo ( $similar_EventId, $similar_info );
} else { // 该主题下事件数目为空或者最高相似度不符合要求,则插入新事件
// 插入新事件
//inseartNewEvent ( $topicId, $infoId, $date );
inseartNewEvent ( $topicId,$row_info);
}
// 信息处理完毕,则修改该信息的processOrNot的值为1
$row_keywordinfo->processornot = 1;
$row_keywordinfo->save();
}
}else{
// 所有未处理的信息都处理完后,休眠10分钟
//sleep ( 10 * 60 );
break;
}
}

/* * 插入新事件
/
function inseartNewEvent($topicId, $info) {
// 在events插入新事件
$row_event = new Event();
$row_event->topic_id = $topicId;
$row_event->start_date = $info->date;
$row_event->end_date = $info->date;
$sentimentWords = json_decode($info->sentimentwords,true);
$positiveWords = $sentimentWords['positive'];
$negativeWords = $sentimentWords['negative'];
$sentimentScore = 0;
if(count($positiveWords)>0){
foreach($positiveWords as $key=>$value){
$sentimentScore += $value;
}
}
if(count($negativeWords)>0){
foreach($negativeWords as $key=>$value){
$sentimentScore += $value;
}
}
$row_event->sentimentscore = $sentimentScore;
$row_event->save();
// 在event_details中插入该事件的一条新记录
$row_eventdetail = new EventDetail();
$row_eventdetail->event_id = $row_event->id;
$row_eventdetail->info_id = $info->id;
$row_eventdetail->save();
}
/
* 在event_details表中为某事件插入新信息,同时修改events表
*/
function inseratNewInfoForEventInfo($eventId, $info) {
// 修改events表中的start_date和end_date
$row_event = Event::find_by_id($eventId);
if ($info->date < $row_event->start_date) {
$row_event->start_date = $info->date;
} else if ($info->date > $row_event->end_date) {
$row_event->end_date = $info->date;
}
$row_event->count = $row_event->count + 1;
$row_event->save();
// 在event_details表中为event增加新消息
$row_eventdetail = new EventDetail();
$row_eventdetail->event_id = $eventId;
$row_eventdetail->info_id = $info->id;
$row_eventdetail->save();
}
?>