Php 无限循环在活动的特定时间后停止

Php 无限循环在活动的特定时间后停止,php,Php,这是我的代码,它有无限循环和睡眠60秒,然后再次从其他网站下载内容。当我在wamp中使用本地机器时,它工作正常,但当我上传此文件时,它在特定时间后不工作,只是停止。我找不到原因是什么 <?php include('scrapconnection.php'); include_once('simple_html_dom.php'); for(;;){ sleep(60); $keyword = "laptop"; $result = mysql_query("select * fr

这是我的代码,它有无限循环和睡眠60秒,然后再次从其他网站下载内容。当我在wamp中使用本地机器时,它工作正常,但当我上传此文件时,它在特定时间后不工作,只是停止。我找不到原因是什么

 <?php include('scrapconnection.php');
include_once('simple_html_dom.php');
 for(;;){
 sleep(60);
 $keyword = "laptop";
 $result = mysql_query("select * from website");
while ($row = mysql_fetch_array($result)) {
$searchLink = $row['searchLink'];
$rootElement = $row['rootElement'];
$productTitle = $row['productTitle'];
$productLink = $row['productLink'];
$productPrice = $row['productPrice'];
$productImage = $row['productImage'];
$productDescription = $row['productDescription'];
$newurl = str_replace("__search_keyword__", $keyword , $searchLink);
$url = $newurl;

$html = file_get_html($url);

$pat[0] = "/^\s+/";
$pat[1] = "/\s{2,}/";
$pat[2] = "/\s+\$/";
$rep[0] = "";
$rep[1] = " ";
$rep[2] = "";


 foreach($html->find("$rootElement") as $heading) { 

    $item['productTitle'] = preg_replace($pat, $rep, $heading->find("$productTitle", 0)->plaintext); 
    $item['productLink'] = preg_replace($pat, $rep, $heading->find("$productLink", 0)->href);
    $item['productImage'] = preg_replace($pat, $rep, $heading->find("$productImage", 0)->src);
    $item['productPrice'] = preg_replace($pat, $rep, $heading->find("$productPrice", 0)->innertext);
    $item['productDescription'] = preg_replace($pat, $rep, $heading->find("$productDescription", 0)->plaintext); 
    preg_match('@^(?:http://www.)?([^/]+)@i',$item['productLink'], $matches);
    $item['domainName'] = $matches[1];
    $articles[] = $item;
    }
 }
  unlink('http://xab.com/files/'.$keyword.'.json');
  $deal=json_encode($articles);

      file_put_contents('http://xab.com/files/'.$keyword.'.json', $deal);
     unset($articles);
    }
?>


这是由于Web服务器超时造成的,我相信没有共享服务器允许脚本运行,即使使用cron。尝试获得具有此执行能力的专用服务器。

尝试将此添加到脚本之上-

ini_set("memory_limit", "-1");

同时签出:

您是否意识到Web服务器有超时?是的,我知道我的Web服务器有50秒超时。我想您的最大执行时间太小了。所以你必须增加它。在php顶部的这一行:ini_set('max_execution_time',300);我想你需要一个CRON任务来实现这个目的谢谢@arjan我以前用过它,但它没有给我任何结果。还有其他方法可以实现吗。我想每10分钟运行一次此页面,以便下载、包含并保存到文件中。为什么不在计算机或本地服务器上编写脚本,每10分钟通过浏览器处理一次?谢谢@parag的支持,但这对我没有帮助。