doutian3269 2015-12-24 17:56
浏览 52
已采纳

如何在目录中搜索并保存在数据库中的许多记录 - php错误

I'm trying to search in a directory some images by offer and then insert them in database. But first, images in directory are many - 35000 and I should search in this directory for all offers - that are 10000. It's showing error:

maximum execution time exceeded in 30 sec

How should I do that?

I'm searching by pattern - by $segment - that is offer id:

if ($dh = opendir($dir))
{
    $array = array();
    while (($file = readdir($dh)) !== false)
    {
        $s = substr($file, strpos($file, $segment), strlen($segment));
        if($s == $segment) {
            $array[] = $file;
        }

        foreach($array as $key) {
            $sql = new sql();

            $sql->query("INSERT INTO offers_images(offer_id, offer_filename) Values ('".$segment."', '".$key."') ");
        }

        closedir($dh);
    }
}

</div>
  • 写回答

2条回答 默认 最新

  • doulun1915 2015-12-24 18:10
    关注

    1) For first, like easy way: You can try use set_time_limit(0) but this option may be disabled on shared hosting. You must check it.

    2) You can make separated multiple "workers" or one "worker" like step by step for small pieces of data.

    3) You can write php script for CLI mode (these unlimited time) and run it as background job.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭