note 93850 added to functions.anonymous
| From: | andrew at evilwalr dot us | Date: | Sat, 03 Oct 2009 05:06:47 +0000 |
| Subject: | note 93850 added to functions.anonymous | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-161244@lists.php.net to get a copy of this message | ||
Very easy way to get the netstat (windows)... yes, this could be a function, but as an example, here
it is in closure form...
<?php
$netstat = function($return = null, $precision = 2) {
// supplement function
$_convert = function ($bytes) use ($precision) {
$i = 0; $iec = array('b', 'kb', 'mb', 'gb',
'tb', 'pb', 'eb', 'zb', 'yb');
while (($bytes / 1024) > 1): $bytes = $bytes / 1024; $i++; endwhile;
return round(substr($bytes, 0, strpos($bytes, '.') + 4), $precision) . '
' . strtoupper($iec[$i]);
};
foreach (explode("\n",
netstat -e) as $d) {
if (preg_match('/^Bytes([\s].+)([0-9])([\s].+)([0-9])/', $d, $m)) {
switch ($return) {
case 'sent': return $_convert(trim($m[1].$m[2])); break;
case 'recv': return $_convert(trim($m[3].$m[4])); break;
default: return array('sent' => $_convert(trim($m[1].$m[2])),
'recv' => $_convert(trim($m[3].$m[4])));
break;
}
}
}
};
?>
----
Server IP: 209.41.74.194
Probable Submitter: 76.117.147.217
----
Manual Page -- http://www.php.net/manual/en/functions.anonymous.php
Edit -- https://master.php.net/note/edit/93850
Del: integrated -- https://master.php.net/note/delete/93850/integrated
Del: useless -- https://master.php.net/note/delete/93850/useless
Del: bad code -- https://master.php.net/note/delete/93850/bad+code
Del: spam -- https://master.php.net/note/delete/93850/spam
Del: non-english -- https://master.php.net/note/delete/93850/non-english
Del: in docs -- https://master.php.net/note/delete/93850/in+docs
Del: other reasons-- https://master.php.net/note/delete/93850
Reject -- https://master.php.net/note/reject/93850
Search -- https://master.php.net/manage/user-notes.php