2012-03-30 57 views
0

我想阻止fsockopen()給我的錯誤。Block fsockopen()錯誤

(警告:的fsockopen()[function.fsockopen]:無法連接到50.31.65.135:27015(連接在/home/reverbga/public_html/query/query.php超時)第6行)

我只是想不顯示,因爲我使用fsockopen作爲一種方式來查看服務器是否聯機。

這是我的代碼:

<?php 
$serialized = file_get_contents('http://module.game-monitor.com/50.31.65.135:27015/data/server.php'); 
$players = unserialize($serialized); 
$array = (array) $players; 

$fp = fsockopen("50.31.65.135", 27015, $errno, $errstr, 1); 

if (!$fp) { 
    echo "<img width='20' height='20' src='bullet_red.png' />OCRP: OFFLINE"; 
} 
else { 
    echo "<img width='20' height='20' src='bullet_green.png' />OCRP: {$array['player']}/{$array['maxplayer']}"; 
} 

?> 

回答

1

您應將的fsockopen處理程序之前使用這樣@符號

<?php 
$serialized = file_get_contents('http://module.game-monitor.com/50.31.65.135:27015/data/server.php'); 
$players = unserialize($serialized); 
$array = (array) $players; 

@$fp = fsockopen("50.31.65.135", 27015, $errno, $errstr, 1); 

if (!$fp) { 
echo "<img width='20' height='20' src='bullet_red.png' />OCRP: OFFLINE"; 
} 
else { 
    echo "<img width='20' height='20' src='bullet_green.png' />OCRP:{$array['player']}/{$array['maxplayer']}"; 
} 

?>