2013-07-14 88 views
0

嘿,我的代码有问题。 它的第一个10名称正常工作,但然后“file_get_contents”返回只是空字符串超时问题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); 

}

>

+0

远程防火墙可能会阻止您。引入一个随机的'睡眠()'延迟 – DevZer0

+0

[不要使用mysql_ * api其弃用所以要么使用PDO或mysqli看到这一点](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql- function-in-php/14110189#14110189) –

回答

-1

file_get_contents()函数外部的URI仅仅是一个巨大的安全问题?这种方法可能会导致很多错误,可能包括你的错误。

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

+0

现在这是错误的。 – DevZer0

+0

实际上,在默认配置中禁用'allow_url_fopen'是有原因的。当然,如果你正在考虑给出更具建设性和详尽的评论,请随时这样做。 –