我正在使用plesk 11.0.9版本。我设置了一个用于更新数据库的cron .cron文件将在一天内运行一次。每次我都要将大量数据(大约20,000)更新到数据库。但是cron文件只运行5分钟并且超时发生。由于这个原因,数据库没有正确更新。我在cron文件中使用了以下代码。
<?php
$query=mysql_query("SELECT id,detail_url,region,region_id FROM c_url_details_crone");
while($ress=mysql_fetch_array($query))
{
echo '---'. $city=$ress['region']; echo "<br>";
$url=$ress['detail_url'];
$did=$ress['id'];
require_once 'simplehtmldom_1_51/simple_html_dom.php';
$html = file_get_html($url);
foreach($html->find('h3[class=h3 z-address]') as $link)
$data['address']= $link;
foreach($html->find('h2[class=z-price brown]') as $pr)
$data['priceH']= $pr;
foreach($html->find('div[class=z-feature]') as $rooms)
$data['room']=$rooms;
foreach($html->find('div[class=z-description]') as $description)
$data['description']=$description;
$property1='';
foreach($html->find('table[class=table-style]') as $property)
{
$property1=$property1. ','.$property;
}
$data['property']=$property1 ;
foreach($html->find('table[class=table-style z-rooms]') as $extras)
{
$data['extras']=$extras;
}
foreach($html->find('li[class=z-mls]') as $listcode)
{
$data['listcode']=$listcode;
}
foreach($html->find('div[class=z-listing-by]') as $propertybrkr)
{
$data['propertybrkr']=$propertybrkr;
}
foreach($html->find('div[class=small-12 columns flat-columns z-block]') as $propertyimages)
$data['propertyimages']=$propertyimages;
if(isset($propertyimages)){ $file_contents= $propertyimages;
$img1='';
foreach(@$file_contents->find('img') as $element)
$img1=$img1. ','.$element->src;
$imgeslidr=explode(',',$img1);
// print_r($imgeslidr);
@$st0=implode(",",$imgeslidr);
}
$detls= explode(',',$property1);
@$dom = new DOMDocument;
@$dom->loadHTML(@$detls[1]);
@$cells = $dom->getElementsByTagName('td');
@$contents = array();
@$aa="";
foreach($cells as $cell)
{
@$contents[] = $cell->nodeValue;
$aa.=$cell->nodeValue.",";
}
@$dom = new DOMDocument;
@$dom->loadHTML(@$detls[1]);
@$cells = $dom->getElementsByTagName('th');
@$contents = array();
$bb='';
foreach($cells as $cell)
{
@$contents1[] = $cell->nodeValue;
$bb.=$cell->nodeValue.",";
}
@$dom = new DOMDocument;
@$dom->loadHTML(@$detls[3]);
@$cells = $dom->getElementsByTagName('th');
@$contents = array();
@$cc="";
foreach($cells as $cell)
{
@$contents2[] = $cell->nodeValue;
$cc.=$cell->nodeValue.",";
}
@$dom = new DOMDocument;
@$dom->loadHTML(@$detls[3]);
@$cells = $dom->getElementsByTagName('td');
@$contents = array();
@$dd="";
foreach($cells as $cell)
{
@$contents3[] = $cell->nodeValue;
$dd.=$cell->nodeValue.",";
}
@$dom = new DOMDocument;
@$dom->loadHTML(@$detls[4]);
@$cells = $dom->getElementsByTagName('th');
@$contents = array();
@$ff="";
foreach($cells as $cell)
{
@$contents5[] = $cell->nodeValue;
$ff.=$cell->nodeValue.",";
}
@$dom = new DOMDocument;
@$dom->loadHTML(@$detls[3]);
@$cells = $dom->getElementsByTagName('thead');
@$contents = array();
@$gg="";
foreach($cells as $cell)
{
@$contents6[] = $cell->nodeValue;
$gg.=$cell->nodeValue.",";
}
@$dom = new DOMDocument;
@$dom->loadHTML(@$detls[4]);
@$cells = $dom->getElementsByTagName('thead');
@$contents = array();
@$hh="";
foreach($cells as $cell)
{
@$contents7[] = $cell->nodeValue;
$hh.=$cell->nodeValue.",";
}
@$dom = new DOMDocument;
@$dom->loadHTML(@$detls[2]);
@$cells = $dom->getElementsByTagName('thead');
@$contents = array();
@$uu="";
foreach($cells as $cell)
{
@$contents8[] = $cell->nodeValue;
$uu.=$cell->nodeValue.",";
}
@$dom = new DOMDocument;
@$dom->loadHTML(@$detls[2]);
@$cells = $dom->getElementsByTagName('th');
@$contents = array();
@$jj="";
foreach($cells as $cell)
{
@$contents9[] = $cell->nodeValue;
$jj.=$cell->nodeValue.",";
}
@$dom = new DOMDocument;
@$dom->loadHTML(@$detls[2]);
@$cells = $dom->getElementsByTagName('td');
@$contents = array();
@$kk="";
foreach($cells as $cell)
{
@$contents10[] = $cell->nodeValue;
$kk.=$cell->nodeValue.",";
}
@$dom = new DOMDocument;
@$dom->loadHTML(@$extras);
@$cells = $dom->getElementsByTagName('td');
@$contents = array();
@$contss="";
foreach($cells as $cell)
{
@$contentsss[] = $cell->nodeValue;
$contss.=$cell->nodeValue."**#**";
}
@$images1=$st0;
@$a1=$aa;
@$b1=$bb;
@$c1=mysql_real_escape_string($cc);
@$d1=mysql_real_escape_string($dd);
@$f1=mysql_real_escape_string($ff);
@$g1=mysql_real_escape_string($gg);
@$h1=mysql_real_escape_string($hh);
@$i1=mysql_real_escape_string($uu);
@$j1=mysql_real_escape_string($jj);
@$k1=mysql_real_escape_string($kk);
@$l1=mysql_real_escape_string($contss);
@$decs=$description;
$c++;
mysql_query("INSERT INTO house_moredetails_crone(city,durl,a,b,c,d,f,g,h,i,j,k,l,description,images)
VALUES('".$city."','".$url."','".$a1."','".$b1."','".$c1."','".$d1."','".$f1."','".$g1."','".$h1."','".$i1."','".$j1."','".$k1."','".$l1."','".$decs."','".$images1."')") ;
mysql_query("DELETE FROM c_url_details_crone WHERE id='$did'");
}
?>
除了用于更新数据库的cron之外还有其他更好的选项。或者通过使用cron是否有任何解决方案来更新数据库而不会超时。等待你的回复!!