【问题标题】:Timeout Issue file_get_contents?超时问题 file_get_contents?
【发布时间】:2013-07-12 10:30:37
【问题描述】:

嘿,我的代码有问题。 它适用于前 10 个名称,但“file_get_contents”只返回空字符串

这是超时问题吗?还是有其他原因?

我该如何解决这个问题?

我的代码:

<?php
$member;

mysql_connect("localhost","**********","********");
mysql_select_db('bf3_ezstats');
$sql = mysql_query('SELECT id, name FROM ez2bf3_player ORDER BY id ASC');

while($row = mysql_fetch_assoc($sql)){
$member[$row['id']] = $row['name'];
}
mysql_close();
print_r($member);

foreach ($member as $ip => $player){
ini_set('default_socket_timeout', 120);
$SC = file_get_contents('http://battlelog.battlefield.com/bf3/user/'.$player);

$SC = split('<surf:container id="profile-gamereport-previews">',$SC);
$SC = split('</surf:container>',$SC[1])[0];

$IPs = array(0=>$player);
while(strpos($SC,'href') !== false){
    $start = strpos($SC,"href");
    $end = strpos($SC,'"',$start+6);
    $IP= substr($SC,$start,$end-$start);
    $IPs[] = "http://battlelog.battlefield.com".str_replace('href="',"",$IP);
    $SC = substr($SC,$end,strlen($SC)-1);
}
print_r($IPs);

}

?>

【问题讨论】:

标签: php timeout file-get-contents


【解决方案1】:

file_get_contents() 在外部 URI 上只是一个巨大的安全问题。这种方法可能会导致许多错误,可能包括您的错误。

如果您需要通过 HTTP 在外部服务器上工作,我强烈建议使用 cURL (http://php.net/manual/fr/book.curl.php)。我想你会发现它更方便,而且你可能会为自己省去很多麻烦。

【讨论】:

  • 实际上,allow_url_fopen 在默认配置中被禁用是有原因的。当然,如果您正在考虑提出更具建设性和详尽的评论,请随时这样做。
猜你喜欢
  • 2012-04-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-13
  • 2011-07-09
  • 1970-01-01
  • 1970-01-01
  • 2011-04-11
相关资源
最近更新 更多