PHP 进程来处理较小的批处理


PHP Process to process smaller batches

我有一个很好的小脚本,它非常原始,目前在php cli中运行良好。如果我尝试在 apache 服务器上加载它,它会给我一个错误,指出它超时,或者无法处理指令。目前,php 文件正在解析页面上 HTML 的特定部分的页面。

有没有办法让它做小批量或使过程更快?我有大约 500-800 个 url 需要处理。

include('./db.php');
$query = "SELECT id,link FROM `1710` order by id ASC";
$result = mysqli_query($con, $query);
if (mysqli_num_rows($result) > 0) {
    while($row = mysqli_fetch_assoc($result)) {
        $link = $row['link'];
        $id = $row['id'];
        $parse = preg_replace("/htt.{1,2}:'/'/(.+?['.'-])*('w{1,61}'.[a-zA-Z]{2,})'/.*/i", "$2", $link);
        if ($parse == 'curseforge.com') {
            $html = file_get_contents($link);
            preg_match('%<li class="view-on-curse">'s+<a href="http:'/'/curse'.com'/project'/(?P<id>.*)">'s+View on Curse'.com's+<'/a>'s+<'/li>%', $html, $matches);
            echo 'https://widget.mcf.li/project/' . $matches['id'] . '.json <br />';
    }
    }
}

查看如何延长允许脚本运行的时间

http://php.net/manual/en/function.set-time-limit.php

<?php
set_time_limit (300);  // 5 minutes