首页 文章

获取3000条数据记录时出现内存不足错误

提问于
浏览
0

我正在尝试使用控制台命令中的zend lucene索引包含超过3000条记录的表

这是我的代码

public function run($args) {
    set_time_limit(0);      
    Yii::import('application.vendors.*');
    require_once 'Zend/Search/Lucene.php';

    Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('utf-8');
    Zend_Search_Lucene_Analysis_Analyzer::setDefault(
            new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive ()
    );

    $searchPath = Yii::app()->runtimePath.'/search';
    $index = Zend_Search_Lucene::create($searchPath);
    /*
     * fecth data to index
     */ 
    $sql = 'select id, title, content, succinct, create_time from `news` where status="published"';
    $query = Yii::app()->db->createCommand($sql);
    $result = $query->queryAll();

    foreach ($result as $data) {
        $doc = new Zend_Search_Lucene_Document();
        $doc->addField(Zend_Search_Lucene_Field::Text('title',
            CHtml::encode($data['title']), 'UTF-8')
        );
        $doc->addField(Zend_Search_Lucene_Field::Text('succinct',
                strip_tags($data['succinct']), 'UTF-8')
        );          
        $doc->addField(Zend_Search_Lucene_Field::UnStored('content',
                strip_tags($data['content']), 'UTF-8')
        );
        $doc->addField(Zend_Search_Lucene_Field::UnIndexed('newsId',
                $data['id'], 'UTF-8')
        );
        $doc->addField(Zend_Search_Lucene_Field::UnIndexed('create_time',
                $data['create_time'], 'UTF-8')
        );
        $index->addDocument($doc);          
    }
    $index->commit();
    $index->optimize(); 
}

}

但是我得到了这个错误

内存不足(需要228480字节)异常'CDbException',消息'CDbCommand无法执行SQL语句:SQLSTATE [HY000]:常规错误:2008 MySQL客户端内存不足 . 执行的SQL语句是:在/home/user/public_html/v2/lib/framework/db/CDbCommand.php:528中选择id,title,content,succinct,create_time from news where status =“published”

有什么建议吗?

1 回答

  • 0

    我刚才有类似的错误 . 我可以通过增加数据库缓存来修复它 . 您还可以尝试增加执行期间php解释器获取的内存量(客户端耗尽内存) . 它也可能对你有帮助 .

相关问题