Skip to content

Instantly share code, notes, and snippets.

@tcz
Created February 24, 2014 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tcz/9188784 to your computer and use it in GitHub Desktop.
Save tcz/9188784 to your computer and use it in GitHub Desktop.
Check request per seconds on Nginx with PHP
<?php
while (true)
{
$query_start = microtime(true);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://127.0.0.1/nginx_status");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Host: whatever-host-name',
));
$rawData = curl_exec($curl);
curl_close($curl);
$query_time = microtime(true) - $query_start;
if (preg_match('/(\d+)\s+(\d+)\s+(\d+)/', $rawData, $m))
{
$new_requests = $m[3] - 1;
if ( isset( $requests ) )
{
echo "RPS: ", (($new_requests-$requests)/(3+$query_time)), "\n";
}
$requests = $new_requests;
}
usleep(3000000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment