PHP脚本检索RSS提要,超时问题


PHP Script to Retrieve RSS Feed, timeout issue

我正在运行一个PHP脚本,该脚本调用世界天气在线检索波高,波持续时间和纬度经度的水温。然而,我的主机只允许10秒的脚本执行。我想知道我是否可以麻烦社区给我一些优化我的脚本的想法/指针,因为我没有访问我的主机上的php_ini。脚本工作,只更新大约35条记录。总共有100条记录。我认为我在世界天气API中投入了太多数据。

下面是我的脚本:
$connection=mysql_connect('myhost', 'user', 'post');
if (!$connection) {  die('Not connected : ' . mysql_error());}

$db_selected = mysql_select_db('ilovebigbutts', $connection);
if (!$db_selected) {
die ('Can''t use db : ' . mysql_error());
}
// Here I am selecting the lat long and pri_id from table
$query = "SELECT * FROM beaches";
$result = mysql_query($query);
if (!$result) {
die("Invalid query: " . mysql_error());
}
while ($row = @mysql_fetch_assoc($result)) {
$id = $row["pri_id"];
$lat = $row["lat"];
$lng = $row["lng"];
$feed_url = "http://free.worldweatheronline.com/feed/marine.ashx?  key=xxxxxxxxxxxx&q=".$lat.",".$lng."&format=xml";
$xmlString = file_get_contents($feed_url);  
$xml = new SimpleXMLElement($xmlString); 
$items = $xml->xpath('weather/hourly');
$closeItems = array(); 
$new_array = array(); 
foreach($items as &$item)  
{ 
$waves = $item->swellHeight_m;
$wave_secs = $item->swellPeriod_secs;
$water_temp = $item->waterTemp_F;
$query1 = "UPDATE beaches SET waves = '$waves', wave_secs = '$wave_secs', water_temp = '$water_temp' WHERE pri_id = '$id' LIMIT 1";
  $update_result = mysql_query($query1);
  if (!$update_result) {
    die("Invalid query: " . mysql_error());
  }
}

}

我很惊讶这花了> 10秒。pri_id上有索引吗?如果需要的话,可以对原始的选择查询设置一个限制,并以块的形式执行。

在优化之前,您是否检查了

<?php
set_time_limit(60); // 1min execution

工作?