Total accesses: 296282 - Total Traffic: 1.2 GB
CPU Usage: u757.94 s165.33 cu0 cs0 - 2.56% CPU load
8.22 requests/sec - 33.5 kB/second - 4175 B/request
22 requests currently being processed, 26 idle workers
Let say we have the above as string and we store that string in a variable. Problem: I want to get the VALUE of the following:
Done some solution using strpos and substr but i dont think its a good solution at all because those values above are dynamic it could be 2 digits or 4 digits or longer.
sample code:
$rps = substr($data,strpos($data,"requests/sec")-5,4);
echo $rps; //displays 8.22
Is there another way to do this? I will appreciate any response :)
Regular expressions.
$values = array();
preg_match("/(?P<rps>[\d.]+) requests\/sec(.*)(?P<requests>[\d]+) requests (.*)(?P<workers>[\d]+) idle workers/", $your_text, $values);
print
"requests/sec - CURRENT VALUE IS {$values['rps']}
requests currently being processed - CURRENT VALUE IS {$values['requests']}
idle workers - CURRENT VALUE IS {$values['workers']}";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With