我有一个非常原始的小脚本,目前可以在 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
关于处理较小批处理的 PHP Process,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35386260/