这应该为每个适配器(输出成对)返回 Rx 和 Tx 的原始值,只有适配器传输了多于零的数据。
<?php
//windows network usage testing
function win_netinfo(){
ob_start();
$wmi = new COM("Winmgmts://");
$nets = $wmi->execquery("SELECT * FROM Win32_PerfRawData_Tcpip_NetworkInterface WHERE BytesSentPersec > 1");
foreach ($nets as $net)
{
$net_txbytes = $net->BytesSentPersec;
$net_rxbytes = $net->BytesReceivedPersec;
if ($net_txbytes < 0) {
$net_txbytes = $net->BytesTotalPersec - $net->BytesReceivedPersec;
}
if ($net_rxbytes < 0) {
$net_rxbytes = $net->BytesTotalPersec - $net->BytesSentPersec;
}
return $net_txbytes . "</br>"; //When it RETURNS it only shows the FIRST value... :/ WHAT DO?
}
}
echo win_netinfo();
?>
输出应该是这样的:
21936313136
12345163517
13647613
87653467
546254
246247
87653642
24583462
(对于每个适配器,每隔一行是 Rx 或 Tx)。
当前有效的代码:
<?php
# Peport All Errors
error_reporting(E_ALL);
# Create Object
$wmi = new COM("Winmgmts://");
# Get net info
$oss = $wmi->execquery("SELECT * FROM Win32_PerfRawData_Tcpip_NetworkInterface");
# Show net info
foreach($oss as $os)
{
echo "BytesReceivedPerSec: " . $os->BytesReceivedPerSec . "<br />";
echo "BytesSentPerSec: " . $os->BytesSentPerSec . "<br />";
echo "BytesTotalPerSec: " . $os->BytesTotalPerSec . "<br />";
echo "Caption: " . $os->Caption . "<br />";
echo "CurrentBandwidth: " . $os->CurrentBandwidth . "<br />";
echo "Description: " . $os->Description . "<br />";
echo "Frequency_Object: " . $os->Frequency_Object . " kb<br />";
echo "Frequency_PerfTime: " . $os->Frequency_PerfTime . "<br />";
echo "Frequency_Sys100NS: " . $os->Frequency_Sys100NS . "<br />";
echo "Name: " . $os->Name . "<br />";
echo "OutputQueueLength: " . $os->OutputQueueLength . "<br />";
echo "PacketsOutboundDiscarded: " . $os->PacketsOutboundDiscarded . "<br />";
echo "PacketsOutboundErrors: " . $os->PacketsOutboundErrors . "<br />";
echo "PacketsReceivedNonUnicastPerSec: " . $os->PacketsReceivedNonUnicastPerSec . "<br />";
echo "PacketsReceivedPerSec: " . $os->PacketsReceivedPerSec . "<br />";
echo "PacketsReceivedUnicastPerSec: " . $os->PacketsReceivedUnicastPerSec . "<br />";
echo "PacketsReceivedUnknown: " . $os->PacketsReceivedUnknown . "<br />";
echo "PacketsSentNonUnicastPerSec: " . $os->PacketsSentNonUnicastPerSec . "<br />";
echo "PacketsSentPerSec: " . $os->PacketsSentPerSec . "<br />";
echo "PacketsSentUnicastPerSec: " . $os->PacketsSentUnicastPerSec . "<br />";
echo "Timestamp_Object: " . $os->Timestamp_Object . "<br />";
echo "Timestamp_PerfTime: " . $os->Timestamp_PerfTime . "<br />";
echo "Timestamp_Sys100NS: " . $os->Timestamp_Sys100NS . "<br />";
echo "<br /><br /><br />";
}
?>