我有以下代码用于从站点提取数据并将其放入sql数据库。它停止在217个条目,但有619个不同的页面。无论我是否回显屏幕或将其存储在数据库中,它都会失败。没有错误信息。file_get_contents停止在217个条目
任何想法为什么?
for($i = 1; $i <= 619; $i++) {
$str = file_get_contents('http://fantasy.mlssoccer.com/web/api/elements/'.$i.'/');
$jsonarray = json_decode($str, true);
//get row data and store in variables
$id = $jsonarray['id'];
$name = addslashes($jsonarray['web_name']);
$team = $jsonarray['team_name'];
$pos = $jsonarray['type_name'];
$flag = $jsonarray['status'];
$cost = ($jsonarray['now_cost']/10);
$ownedby = $jsonarray['selected'];
$balance = $jsonarray['transfers_balance'];
$playerupdate = mysql_query("
INSERT INTO playerprices (id, name, team, pos, flag, cost, ownedby, balance)
VALUES ('$id', '$name', '$team', '$pos', '$flag', '$cost', '$ownedby', '$balance')
ON DUPLICATE KEY UPDATE flag = '$flag', cost = '$cost', ownedby = '$ownedby', balance = '$balance'")
or die (mysql_error());
}
当我回声仅216-220页中的变量,他们都做工精细,所以我不认为这是与这些页面上的数据做。没有我能看到的特殊字符。
剧本超时?尝试在200美元开始$ i,看看会发生什么 – Oli 2013-03-05 22:57:21
@oli有它的权利我敢打赌。查看[set_time_limit](http://php.net/manual/en/function.set-time-limit.php),并希望您的主机允许您更改它。 – mkaatman 2013-03-05 22:58:30
或者,从命令行(PHP CLI)运行它。超时限制不适用于命令行脚本 – xbonez 2013-03-05 22:59:26