有没有办法有效地运行/编写下面的代码?
当我运行它(通过 chrome 浏览器)时,总是倾向于在第 500 项左右超时并将我重定向回我的主页。
<?php
include_once('config.php');
include_once('simple_html_dom.php');
for($i = 0; $i <= 5000; ++$i){
// Retrieve the DOM from a given URL
$html = file_get_html($url);
// Loop that checks through page contents and retrieves all required
foreach($html->find('div.product-details-contents') as $content) {
$detail['productid'] = $i;
$detail['title'] = $content->find('span.title', 0)->plaintext;
$detail['unit'] = $content->find('span.unit-size', 0)->plaintext;
$sqlstring = implode("','", $detail);
$sql = "INSERT INTO `cdidlist` (`productid`, `title`, `unit`) VALUES ('$sqlstring')";
if (!mysqli_query($connect, $sql)) {
echo "Error: " . mysqli_error();
}
echo $id . " " . $detail['title'] . " Item Added SUCSESSFULLY! <br>";
}
}
?>