doukun8670 2016-02-25 23:16
浏览 42
已采纳

检测语言; CakePHP更新所有不良性能

UPDATE: I think the cakePhp updateAll is the problem. If i uncomment the updateAll and pr the results i get in 1-2 seconds so many language Detections like in 5 minutes!!!! I only must update one row and can determine that row with author and title... is there a better and faster way???

I'm using detectlanguage.com in order to detect all english texts in my sql database. My Database consists of about 500.000 rows. I tried many things to detect the lang of all my texts faster. Now it will take many days... :/

  • i only send 20% of the text (look at my code)
  • i tried to copy my function and run the function many times. the copied code shows the function for all texts with a title starting with A

I only can run 6 functions at the same time... (localhost)... i tried a 7th function in a new tab, but

Waiting for available socket....

     public function detectLanguageA()
{
    set_time_limit(0);
    ini_set('max_execution_time', 0);

    $mydatas = $this->datas;

    $alldatas = $mydatas->find('all')->where(['SUBSTRING(datas.title,1,1) =' => 'A'])->where(['datas.lang =' => '']);

    foreach ($alldatas as $row) {
    $text = $row->text;
    $textLength = round(strlen($text)*0.2);
    $text = substr($text,0,$ltextLength);
        $title = $row->title;
    $author = $row->author;
            $languageCode = DetectLanguage::simpleDetect($text);

    $mydatas->updateAll(
                ['lang' => $languageCode], // fields
                ['author' => $author,'textTitle' => $title]); // conditions*/

    }
}

I hope some one has a idea for my problem... Now the language detection for all my texts will take more than one week :/ :/

My computer runs over 20 hours with only little interruptions... But i only detected the language of about 13.000 texts... And in my database are 500.000 texts...

  • Now i tried sending texts by batch, but its also to slow... I always send 20 texts in one Array and i think thats the maximum...

Is it possible that the cakePhp 3.X updateAll-function makes it so slowly?

  • 写回答

1条回答 默认 最新

  • drdawt9210 2016-02-26 12:59
    关注

    THE PROBLEM WAS THE CAKEPHP updateAll

    Now i'm using: http://book.cakephp.org/3.0/en/orm/saving-data.html#updating-data with a for loop and all is fast and good

    use Cake\ORM\TableRegistry;
    
     $articlesTable = TableRegistry::get('Articles');
    
        for ($i = 1; $i < 460000; $i++) {
            $oneArticle = $articlesTable->get($i);
    
            $languageCode = DetectLanguage::simpleDetect($oneArticle->lyrics);
    
            $oneArticle->lang = $languageCode;
            $articlesTable->save($oneSong);
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示