Information système php

Fermé
fff - 31 juil. 2011 à 18:29
Groarh Messages postés 682 Date d'inscription vendredi 1 août 2008 Statut Membre Dernière intervention 28 juin 2015 - 2 août 2011 à 15:25
Bonjour,
j'ai trouvé ce code censé afficher les informations systèmes mais il ne marche pas je suis sous serveur LAMP

voici le code :

<?php
error_reporting(5);

class systeme {
  // --- retourne un tableau indiquant la charge système
  function infos_charge() {
    if ($fd = fopen("/proc/loadavg", "r")) {
      $results = split(" ", fgets($fd, 4096));
      fclose($fd);
    }
    else {
      $results = array("xx","xx","xx");
    }
    return $results;
  }

   // --- retourne la valeur de uptime
  function infos_uptime() {
    $fd = fopen("/proc/uptime", "r");
    $tmptb = split(" ", fgets($fd, 4096));
    fclose($fd);
    $secondes = trim($tmptb[0]);
    $min = $secondes / 60;
    $heures = $min / 60;
    $jours = floor($heures / 24);
    $heures = floor($heures - ($jours * 24));
    $min = floor($min - ($jours * 60 * 24) - ($heures * 60));
    if ($days != 0) {
      $result = "$jours jours, ";
    }
    if ($hours != 0) {
      $result .= "$heures heures, ";
    }
    $result .= "$min minutes";
    return $result;
  }
  // --- retourne le nombre de sessions Apache
  function infos_apache() {
    $result = trim('ps -e | fgrep httpd |  wc -l');
    return $result;
  }

  // --- retourne des informations sur la CPU
  function infos_cpu() {
    $results = array();
    $tmptb = array();
    if ($fd = fopen("/proc/cpuinfo", "r")) {
      while ($buf = fgets($fd, 4096)) {
        list($key, $value) = preg_split("/\s+:\s+/", trim($buf), 2);
        switch ($key) {
          case "model name":
            $results['model'] = $value;
            break;
          case "cpu MHz":
            $results['mhz'] = sprintf("%.2f", $value);
            break;
          case "clock":
            $results['mhz'] = sprintf("%.2f", $value);
            break;
          case "cpu":
             $results['model'] = $value;
             break;
          case "revision":
             $results['model'] .= " (rev: " . $value . ")";
             break;
          case "cache size":
             $results['cache'] = $value;
             break;
          case "bogomips":
             $results['bogomips'] += $value;
             break;
          case "processor":
             $results['cpus'] += 1;
             break;
        }
      }
      fclose($fd);
    }
    $keys = compat_array_keys($results);
    $keys2be = array("model", "mhz", "cache", "bogomips", "cpus");
    while ($tmptb = each($keys2be)) {
      if (!compat_in_array($tmptb[1], $keys)) {
       $results[$tmptb[1]] = 'N.A.';
      }
    }
    return $results;
  }
  // --- informations sur la mémoire et la zone de swap
  function infos_memoire() {
    if ($fd = fopen("/proc/meminfo", "r")) {
      while ($buf = fgets($fd, 4096)) {
        if (preg_match("/Mem:\s+(.*)$/", $buf, $tmptb)) {
          $tmptb = preg_split("/\s+/", $tmptb[1], 6);
          $results['ram'] = array();
          $results['ram']['total'] = $tmptb[0] / 1024;
          $results['ram']['used'] = $tmptb[1] / 1024;
          $results['ram']['free'] = $tmptb[2] / 1024;
          $results['ram']['shared'] = $tmptb[3] / 1024;
          $results['ram']['buffers'] = $tmptb[4] / 1024;
          $results['ram']['cached'] = $tmptb[5] / 1024;
          $results['ram']['t_used'] = $results['ram']['used']
            - $results['ram']['cached']
            - $results['ram']['buffers'];
          $results['ram']['t_free'] = $results['ram']['total']
            - $results['ram']['t_used'];
          $results['ram']['percent'] = round(
            ($results['ram']['t_used'] * 100)
            / $results['ram']['total']);
        }
        if (preg_match("/Swap:\s+(.*)$/", $buf, $tmptb)) {
          $tmptb = preg_split("/\s+/", $tmptb[1], 3);
          $results['swap'] = array();
          $results['swap']['total'] = $tmptb[0] / 1024;
          $results['swap']['used'] = $tmptb[1] / 1024;
          $results['swap']['free'] = $tmptb[2] / 1024;
          $results['swap']['percent'] = round(($tmptb[1] * 100)
            / $tmptb[0]);
          break;
        }
      }
      fclose($fd);
    }
    else {
      $results['ram'] = array();
      $results['swap'] = array();
    }
    return $results;
  }

  // --- Retourne un tableau avec les informations sur chaque
  // partition. Ces informations sont elles-mêmes stockées
  // dans un tableau associatif
  function infos_disque() {
    $df = '/bin/df -kP';
    $mounts = split("\n", $df);
    $fstype = array();
    if ($fd = fopen("/proc/mounts", "r")) {
      while ($buf = fgets($fd, 4096)) {
        list($dev, $mpoint, $type) = preg_split("/\s+/", trim($buf), 4);
        $fstype[$mpoint] = $type;
        $fsdev[$dev] = $type;
      }
      fclose($fd);
    }
    for ($i = 1; $i < sizeof($mounts) - 1; $i++) {
      $tmptb = preg_split("/\s+/", $mounts[$i], 6);
      $results[$i - 1] = array();
      $results[$i - 1]['disk'] = $tmptb[0];
      $results[$i - 1]['size'] = $tmptb[1];
      $results[$i - 1]['used'] = $tmptb[2];
      $results[$i - 1]['free'] = $tmptb[3];
      $results[$i - 1]['percent'] = $tmptb[4];
      $results[$i - 1]['mount'] = $tmptb[5];
      ($fstype[$tmptb[5]]) ? $results[$i - 1]['fstype'] =
        $fstype[$tmptb[5]] : $results[$i - 1]['fstype'] =
        $fsdev[$tmptb[0]];
    }
    return $results;
  }

  // --- fonction de formattage
  function format_ko($ko, $decimales = 2) {
    if ($ko > 1048576) {
      $result = sprintf("%." . $decimales . "f", $ko / 1048576);
      $result .= ' Go';
    }
    elseif ($ko > 1024) {
      $result = sprintf("%." . $decimales . "f", $ko / 1024);
      $result .= ' Mo';
    }
    else {
      $result = sprintf("%." . $decimales . "f", $ko);
      $result .= ' Ko';
    }
    return $result;
  }

}
?> 


merci d'avance
bonne soirée
A voir également:

5 réponses

Groarh Messages postés 682 Date d'inscription vendredi 1 août 2008 Statut Membre Dernière intervention 28 juin 2015 185
31 juil. 2011 à 19:23
Salut,

ça serait bien que tu nous dises déjà qu'est-ce qui te fait dire que ça ne marche pas, les différents trucs que tu as essayé et les résultats ou messages d'erreur que tu as obtenus, etc. Sans un minimum d'informations, on ne peut pas tellement t'aider ;)
0
voici le message d'erreur affiché :

[Mon Aug 01 14:05:16 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 24
[Mon Aug 01 14:05:16 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 25
[Mon Aug 01 14:05:16 2011] [error] [client 192.168.1.29] PHP Warning: Division by zero in /var/www/test IS.php on line 32
[Mon Aug 01 14:05:16 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 38
[Mon Aug 01 14:05:16 2011] [error] [client 192.168.1.29] PHP Warning: Division by zero in /var/www/test IS.php on line 39
[Mon Aug 01 14:05:16 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 39
[Mon Aug 01 14:05:16 2011] [error] [client 192.168.1.29] PHP Warning: Division by zero in /var/www/test IS.php on line 45
[Mon Aug 01 14:05:16 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 51
[Mon Aug 01 14:05:16 2011] [error] [client 192.168.1.29] PHP Warning: Division by zero in /var/www/test IS.php on line 52
[Mon Aug 01 14:05:16 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 52
[Mon Aug 01 14:05:16 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 64
[Mon Aug 01 14:05:16 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 65
[Mon Aug 01 14:05:23 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 24
[Mon Aug 01 14:05:23 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 25
[Mon Aug 01 14:05:23 2011] [error] [client 192.168.1.29] PHP Warning: Division by zero in /var/www/test IS.php on line 32
[Mon Aug 01 14:05:23 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 38
[Mon Aug 01 14:05:23 2011] [error] [client 192.168.1.29] PHP Warning: Division by zero in /var/www/test IS.php on line 39
[Mon Aug 01 14:05:23 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 39
[Mon Aug 01 14:05:23 2011] [error] [client 192.168.1.29] PHP Warning: Division by zero in /var/www/test IS.php on line 45
[Mon Aug 01 14:05:23 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 51
[Mon Aug 01 14:05:23 2011] [error] [client 192.168.1.29] PHP Warning: Division by zero in /var/www/test IS.php on line 52
[Mon Aug 01 14:05:23 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 52
[Mon Aug 01 14:05:23 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 64
[Mon Aug 01 14:05:23 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 65
[Mon Aug 01 14:05:30 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 24
[Mon Aug 01 14:05:30 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 25
[Mon Aug 01 14:05:30 2011] [error] [client 192.168.1.29] PHP Warning: Division by zero in /var/www/test IS.php on line 32
[Mon Aug 01 14:05:30 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 38
[Mon Aug 01 14:05:30 2011] [error] [client 192.168.1.29] PHP Warning: Division by zero in /var/www/test IS.php on line 39
[Mon Aug 01 14:05:30 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 39
[Mon Aug 01 14:05:30 2011] [error] [client 192.168.1.29] PHP Warning: Division by zero in /var/www/test IS.php on line 45
[Mon Aug 01 14:05:30 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 51
[Mon Aug 01 14:05:30 2011] [error] [client 192.168.1.29] PHP Warning: Division by zero in /var/www/test IS.php on line 52
[Mon Aug 01 14:05:30 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 52
[Mon Aug 01 14:05:30 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 64
[Mon Aug 01 14:05:30 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 65
[Mon Aug 01 14:05:30 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 24
[Mon Aug 01 14:05:30 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 25
[Mon Aug 01 14:05:30 2011] [error] [client 192.168.1.29] PHP Warning: Division by zero in /var/www/test IS.php on line 32
[Mon Aug 01 14:05:30 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 38
[Mon Aug 01 14:05:30 2011] [error] [client 192.168.1.29] PHP Warning: Division by zero in /var/www/test IS.php on line 39
[Mon Aug 01 14:05:30 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 39
[Mon Aug 01 14:05:30 2011] [error] [client 192.168.1.29] PHP Warning: Division by zero in /var/www/test IS.php on line 45
[Mon Aug 01 14:05:30 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 51
[Mon Aug 01 14:05:30 2011] [error] [client 192.168.1.29] PHP Warning: Division by zero in /var/www/test IS.php on line 52
[Mon Aug 01 14:05:30 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 52
[Mon Aug 01 14:05:30 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 64
[Mon Aug 01 14:05:30 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 65
[Mon Aug 01 14:09:26 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 24
[Mon Aug 01 14:09:26 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 25
[Mon Aug 01 14:09:26 2011] [error] [client 192.168.1.29] PHP Warning: Division by zero in /var/www/test IS.php on line 32
[Mon Aug 01 14:09:26 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 38
[Mon Aug 01 14:09:26 2011] [error] [client 192.168.1.29] PHP Warning: Division by zero in /var/www/test IS.php on line 39
[Mon Aug 01 14:09:26 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 39
[Mon Aug 01 14:09:26 2011] [error] [client 192.168.1.29] PHP Warning: Division by zero in /var/www/test IS.php on line 45
[Mon Aug 01 14:09:26 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 51
[Mon Aug 01 14:09:26 2011] [error] [client 192.168.1.29] PHP Warning: Division by zero in /var/www/test IS.php on line 52
[Mon Aug 01 14:09:26 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 52
[Mon Aug 01 14:09:26 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 64
[Mon Aug 01 14:09:26 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 65
[Mon Aug 01 14:09:27 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 24
[Mon Aug 01 14:09:27 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 25
[Mon Aug 01 14:09:27 2011] [error] [client 192.168.1.29] PHP Warning: Division by zero in /var/www/test IS.php on line 32
[Mon Aug 01 14:09:27 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 38
[Mon Aug 01 14:09:27 2011] [error] [client 192.168.1.29] PHP Warning: Division by zero in /var/www/test IS.php on line 39
[Mon Aug 01 14:09:27 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 39
[Mon Aug 01 14:09:27 2011] [error] [client 192.168.1.29] PHP Warning: Division by zero in /var/www/test IS.php on line 45
[Mon Aug 01 14:09:27 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 51
[Mon Aug 01 14:09:27 2011] [error] [client 192.168.1.29] PHP Warning: Division by zero in /var/www/test IS.php on line 52
[Mon Aug 01 14:09:27 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 52
[Mon Aug 01 14:09:27 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 64
[Mon Aug 01 14:09:27 2011] [error] [client 192.168.1.29] PHP Warning: imagettftext(): Could not find/open font in /var/www/test IS.php on line 65
0
Groarh Messages postés 682 Date d'inscription vendredi 1 août 2008 Statut Membre Dernière intervention 28 juin 2015 185
1 août 2011 à 15:05
Ok... Ne le prends pas mal, mais je crois que c'est toi qu'il faut débugger, pas ton programme :P
Tu ne nous as pas donné le bon code source. Les erreurs parlent d'un fichier test IS.php, je voudrais le voir. D'autre part, comment s'appelle le fichier qui contient le code que tu as donné ?

De plus, le niveau d'erreur que tu as spécifié (5) ne permet pas de tout voir (tu n'as ni warning ni notice). Remplace-le par -1 et refais tes tests, et montre-moi les nouveaux messages d'erreur.

error_reporting(-1);
0
le fichier test IS.php contient le code que j'ai posté dans mon tout premier message voici le log d'erreur avec le niveau -1 :

arning: include_once(classe_systeme.php) [function.include-once]: failed to open stream: No such file or directory in C:\UwAmp\www\test IS.php on line 183
Call Stack
# Time Memory Function Location
1 0.0029 422928 {main}( ) ..\test IS.php:0


( ! ) Warning: include_once() [function.include]: Failed opening 'classe_systeme.php' for inclusion (include_path='.;C:\php\pear') in C:\UwAmp\www\test IS.php on line 183
Call Stack
# Time Memory Function Location
1 0.0029 422928 {main}( ) ..\test IS.php:0


( ! ) Warning: fopen(/proc/loadavg) [function.fopen]: failed to open stream: No such file or directory in C:\UwAmp\www\test IS.php on line 8
Call Stack
# Time Memory Function Location
1 0.0029 422928 {main}( ) ..\test IS.php:0
2 0.0063 423624 systeme->infos_charge( ) ..\test IS.php:187
3 0.0063 423760 fopen ( ) ..\test IS.php:8


( ! ) Warning: fopen(/proc/loadavg) [function.fopen]: failed to open stream: No such file or directory in C:\UwAmp\www\test IS.php on line 8
Call Stack
# Time Memory Function Location
1 0.0029 422928 {main}( ) ..\test IS.php:0
2 0.0072 424504 systeme->infos_charge( ) ..\test IS.php:192
3 0.0073 424640 fopen ( ) ..\test IS.php:8


( ! ) Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Paris' for '2.0/DST' instead in C:\UwAmp\www\test IS.php on line 193
Call Stack
# Time Memory Function Location
1 0.0029 422928 {main}( ) ..\test IS.php:0
2 0.0082 425016 date ( ) ..\test IS.php:193


( ! ) Notice: Undefined variable: durée in C:\UwAmp\www\test IS.php on line 194
Call Stack
# Time Memory Function Location
1 0.0029 422928 {main}( ) ..\test IS.php:0


( ! ) Warning: fopen(/proc/meminfo) [function.fopen]: failed to open stream: No such file or directory in C:\UwAmp\www\test IS.php on line 91
Call Stack
# Time Memory Function Location
1 0.0029 422928 {main}( ) ..\test IS.php:0
2 0.0093 425224 systeme->infos_memoire( ) ..\test IS.php:199
3 0.0093 425360 fopen ( ) ..\test IS.php:91


( ! ) Notice: Undefined index: percent in C:\UwAmp\www\test IS.php on line 200
Call Stack
# Time Memory Function Location
1 0.0029 422928 {main}( ) ..\test IS.php:0


( ! ) Deprecated: Function split() is deprecated in C:\UwAmp\www\test IS.php on line 136
Call Stack
# Time Memory Function Location
1 0.0029 422928 {main}( ) ..\test IS.php:0
2 0.0111 425272 systeme->infos_disque( ) ..\test IS.php:204


( ! ) Warning: fopen(/proc/mounts) [function.fopen]: failed to open stream: No such file or directory in C:\UwAmp\www\test IS.php on line 138
Call Stack
# Time Memory Function Location
1 0.0029 422928 {main}( ) ..\test IS.php:0
2 0.0111 425272 systeme->infos_disque( ) ..\test IS.php:204
3 0.1699 425776 fopen ( ) ..\test IS.php:138


( ! ) Notice: Undefined variable: results in C:\UwAmp\www\test IS.php on line 159
Call Stack
# Time Memory Function Location
1 0.0029 422928 {main}( ) ..\test IS.php:0
2 0.0111 425272 systeme->infos_disque( ) ..\test IS.php:204
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
Groarh Messages postés 682 Date d'inscription vendredi 1 août 2008 Statut Membre Dernière intervention 28 juin 2015 185
2 août 2011 à 15:25
Salut,

tu as des chemins de fichiers de type Windows (C:\UwAmp\www\test IS.php). Ça ne vient pas de LAMP ! Si tu es sous Windows, aucune chance que des accès à /proc/loadavg puissent fonctionner.

D'autre part,
Warning: include_once(classe_systeme.php)
... in C:\UwAmp\www\test IS.php on line 183

Il n'y a aucun appel à include_once dans le code que tu as donné. D'ailleurs, il ne fait même pas 183 lignes. C'est pourquoi je pense que le code que tu as donné n'est pas celui du fichier test IS.php... Donc je ne peux toujours pas t'aider pour l'instant.

Je pense qu'il te manque des notions essentielles en PHP, et il serait bon que tu suives deux ou trois tutos avant de demander de l'aide ;)
0