PHP Classes

PHP Network Monitor: Monitor the statistics of network interfaces

Recommend this page to a friend!
  Info   View files Example   View files View files (7)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 120 All time: 9,444 This week: 96Up
Version License PHP version Categories
php-network-monitor 1.0.0Custom (specified...5Networking, Unix, PHP 8


This package can monitor the statistics of network interfaces.

It can check the available network interfaces in the current computer running under a Linux-based operating system.

The package can also retrieve statistics about a given network interface using the vnstat program or checking system virtual files containing values of several types of statistics of the traffic that goes through the specified network interface, like the number of transmitted bytes.

Innovation Award
PHP Programming Innovation award nominee
June 2021
Number 6
Monitoring aspects of a server running on the Internet can be useful to diagnose problems that need to be fixed quickly to avoid causing damages to businesses that depend on that server.

This package implements a solution to monitor network connections on a given Linux server using the vnstat program or checking the system virtual files related with networking connections.

Manuel Lemos
Picture of Isa Eken
  Performance   Level  
Name: Isa Eken <contact>
Classes: 20 packages by
Country: Turkey Turkey
Age: 21
All time rank: 280845 in Turkey Turkey
Week rank: 44 Up4 in Turkey Turkey Up
Innovation award
Innovation award
Nominee: 13x



use IsaEken\NetworkMonitor\NetworkMonitor;

__DIR__ . '/../vendor/autoload.php';

if (
header('Content-Type: application/json');

    if (!
NetworkMonitor::hasInterface($_POST['interface'] ?? '')) {
        return print
json_encode((object) [
'name' => null,
'directory' => null,
'statistics' => (object) [],

$interface = NetworkMonitor::findInterface($_POST['interface'] ?? '');
    return print
json_encode((object) [
'name' => $interface->getName(),
'directory' => $interface->directory,
'statistics' => (object) $interface->statistics()->toArray(),

$composer = json_decode(file_get_contents(__DIR__ . '/../composer.json'));
$version = $composer->version;
$title = sprintf('Network Monitor - v%s', $version);

?><!doctype html>
<html lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title><?= $title ?></title>
    <link rel="stylesheet" href="" integrity="sha512-ghzNCvgK81aIdKyuTnLazeFEzs2F8AHLWyCYsvJHPqgGf8OpS/yRrq6seFxik5n08mjRmX8ETGPrHKkDkwBekw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
    <script src="" integrity="sha512-nIwdJlD5/vHj23CbO2iHCXtsqzdTTx3e3uAmpTm4x2Y8xCIFyWu4cSIV8GaGe2UNVq86/1h9EgUZy7tn243qdA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
    <script src="" integrity="sha512-bZS47S7sPOxkjU/4Bt0zrhEtWx0y0CRkhEp8IckzK+ltifIIE9EMIMTuT/mEzoIMewUINruDBIR/jJnbguonqQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<body class="bg-gray-900 text-gray-100 min-w-screen">
<div class="max-w-4xl my-12 mx-auto space-y-4" x-data="data()">
        <div class="text-2xl">
            <?= $title ?>
        <div class="text-xl">
            <span class="text-xs mr-2">developed by</span><a href="" target="_blank">Isa Eken</a>
        <label for="interfaces">Select Interface</label>
        <select x-on:change="interface = $; updateInterval(); load();" name="interfaces" id="interfaces" class="block w-full py-2 text-gray-700">
            <?php foreach (NetworkMonitor::getInterfaces() as $interface): ?>
<option x-bind:value="'<?= $interface->getName() ?>'" value="<?= $interface->getName() ?>" <?= $interface->getName() === 'eth0' ? 'selected' : '' ?>>
                    <?= $interface->getName() ?>
            <?php endforeach; ?>
        <label for="refresh">Refresh</label>
        <select x-on:change="interval = $; updateInterval(); load();" name="refresh" id="refresh" class="block w-full py-2 text-gray-700">
            <?php $index = 0; foreach ([0, 5, 15, 30, 60, 300, 1800, 3600, 43200] as $seconds): ?>
<option x-bind:value="<?= $seconds ?>" value="<?= $seconds ?>" <?= $index++ === 0 ? 'selected' : '' ?>>
if ($seconds === 0) {
'No refresh';
                    else {
$datetime1 = new DateTime('@0');
$datetime2 = new DateTime("@$seconds");
$datetime1->diff($datetime2)->format('%a days, %h hours, %i minutes and %s seconds');
            <?php endforeach; ?>
    <div class="text-xl" x-show="time_left !== null && time_left > 0">
        Refreshing in <span x-text="time_left" id="time_left">0</span> seconds
        <div id="interface_name" x-text="interface" class="mb-4 text-xl"></div>
        <table class="w-full">
            <template x-for="item in statistics">
                <tr class="hover:bg-gray-800">
                    <td class="py-2" x-text="item[0]"></td>
                    <td class="py-2" x-text="item[1]"></td>
    <div class="mb-4">
            Please run
            <code class="bg-black rounded text-sm mx-2 px-2 py-1 select-all">sudo apt-get install vnstat</code>
            <code class="bg-black rounded text-sm mx-2 px-2 py-1 select-all">sudo service vnstat enable && sudo service vnstat start</code>
            for the app to work properly.
        let int = 'eth0';
        let statistics = [];

        function load() {
            loadData(document.querySelector('[x-data]').__x.$data.interface).then(function (data) {
                document.querySelector('[x-data]').__x.$data.statistics = data;

        function data() {
            return {
                interface: int,
                statistics: statistics,
                time_left: 0,
                time_left__: null,
                interval: 0,
                interval__: null,
                updateInterval: function () {
                    this.time_left = this.interval;
                    let time_left = this.time_left;
                    let interval = this.interval;


                    if (interval > 1) {
                        this.interval__ = setInterval(function () {
                            time_left = interval;
                        }, interval * 1000);

                        this.time_left__ = setInterval(function () {
                            time_left = time_left - 1;
                            document.getElementById('time_left').textContent = time_left;
                        }, 1000);

                    this.time_left = time_left;
                load: function () {

        async function loadData(interfaceName) {
            let statistics = [];
            const params = new URLSearchParams();
            params.append('interface', interfaceName);

            await axios({
                method: 'POST',
                url: '<?= (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http') . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]" ?>',
                data: params,
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded',
            }).then(function (response) {
                statistics = Object.entries(;

            return statistics;

  Files folder image Files  
File Role Description
Files folder imagebin (1 file)
Files folder imagepublic (1 file)
Files folder imagesrc (2 files)
Plain text file composer.json Data Auxiliary data
Plain text file Lic. License text
Plain text file Doc. Documentation

  Files folder image Files  /  bin  
File Role Description
  Plain text file monitor.php Example Example script

  Files folder image Files  /  public  
File Role Description
  Plain text file index.php Example Example script

  Files folder image Files  /  src  
File Role Description
  Plain text file NetworkInterface.php Class Class source
  Plain text file NetworkMonitor.php Class Class source

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:9,444
This week:96Up