Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way that I can monitor the traffic, Upload/Download (separately) using PHP? I`d like to echo out something like that:

Upload: 523 GB | Download: 25 GB

This should be based on the System Uptime, so if I restart the computer, the count should restart.

Thanks in Advance.

share|improve this question
If you want accurate answers, you need to give more information about your environment. – EEAA Mar 27 '10 at 22:41

Just run ifconfig from within php and parse out the TX/RX fields.

Another option would be to use the php snmp libraries and query the ifinoctet and ifoutoctet OIDs.

share|improve this answer
But the problem is, I need it for Windows (more exactly Windows 7) – user38997 Mar 27 '10 at 22:38
The snmp solution would still work for windows. You'd need to set up the SNMP service if it's already not running. – EEAA Mar 27 '10 at 22:40
Do I need to install something for php? I get a function error. "Fatal error: Call to undefined function snmpget() in D:\WinServer\xampp\htdocs\network\index.php on line 12" Line 12: $sysname[0] = snmpget($sysip[$i], $snmpcommunity, "sysName.0"); – user38997 Mar 27 '10 at 23:53
You need the PHP-SNMP module installed and configured. If this is for production use, Use MRTG, or cacti, or one of the many monitoring programs to do this. Don't home grow it. – Richard June Mar 28 '10 at 8:17

You could write a script that parses the RX and TX counters from ifconfig (on a Linux box), those get reset on boot. The only problem is that it wont be just HTTP traffic, it's a global counter for all traffic on the box.

share|improve this answer
Yes, thanks no problem I need the global counter, not only HTTP. Thanks a lot. – user38997 Mar 27 '10 at 22:30

ever consider looking at nagios? Free open source monitoring tool. We use it extensively at work to monitor all sorts of things

share|improve this answer

I think *mod_cband* could do the trick. I don't know if it works on Hasefroch but you could try it...

Edit: Oh, I see that you need a global counter so ifconfig would be the way. I don't like PHP doing system calls so what about a C daemon writing a log file that would be readed by PHP?


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.