我在工作中創建一個PHP遠程登錄腳本以收集網絡數據時遇到了問題。PHP fread問題
從'Action:Status'命令返回的數據量可以是任意大小...我關心在第13行使用帶有fread()的靜態數字。我也嘗試過使用fgets()但它只抓取第一行數據(META HTTP行......沒有表格)。我怎樣才能使用PHP從套接字中獲取任意數量的數據?請幫助
<?php
$ami = fsockopen("192.100.100.180", 5038, $errno, $errstr);
if (!$ami) {
echo "ERROR: $errno - $errstr<br />\n";
} else {
fwrite($ami, "Action: Login\r\nUsername: 1005\r\nSecret: password\r\nEvents: off\r\n\r\n");
fwrite($ami, "Action: Status\r\n\r\n");
sleep(1);
$record = fread($ami,9999);#this line could over run!!!
$record = explode("\r\n", $record);
echo "<META HTTP-EQUIV=Refresh CONTENT=\"9\">"; #refresh page every 9 seconds
echo "<table border=\"1\">";
foreach($record as $value){
if(!strlen(stristr($value,'Asterisk'))>0
&& !strlen(stristr($value,'Response'))>0
&& !strlen(stristr($value,'Message'))>0
&& !strlen(stristr($value,'Event'))>0
&& strlen(strpos($value,' '))>0) #remove blank lines
php_table($value);;
}
echo "</table>";
fclose($ami);
}
function php_table($value){
$row1 = true;
$value = explode(" ", $value);
foreach($value as $field){
if($row1){
echo "<tr><td>".$field."</td>";
$row1 = false;
}
else{
echo "<td>".$field."</td></tr>";
$row1 = true;
}
}
}
?>
http://stackoverflow.com/questions/1405457/php-soap-fread-dynamic-post-size有一個類似的問題,這可能有助於 – 2010-10-15 14:54:52
感謝phill,我試着測試頭,但問題最終與離開會話打開 – JB87 2010-10-15 15:27:05