Added “showrem” parameter to make it possible to monitor remaining hits
This commit is contained in:
parent
30c314948c
commit
c7eacfb643
1 changed files with 2 additions and 1 deletions
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
function ckratelimit($headers) {
|
||||
function ckratelimit($headers,$showrem=false) {
|
||||
$aaheaders=[];
|
||||
array_shift($headers);
|
||||
foreach ($headers as $header)
|
||||
|
@ -13,6 +13,7 @@ function ckratelimit($headers) {
|
|||
if (!isset($aaheaders['x-ratelimit-remaining'])) return ['ok'=>false,'error'=>'no «x-ratelimit-remaining» header'];
|
||||
if (preg_match('#^\d+$#',$aaheaders['x-ratelimit-remaining'])!==1) return ['ok'=>false,'error'=>'«x-ratelimit-remaining» header is not an integer'];
|
||||
$remaining=$aaheaders['x-ratelimit-remaining']+0;
|
||||
if ($showrem) echo "ckratelimit: remaining: {$remaining}\n";
|
||||
$date=@strtotime($aaheaders['date']);
|
||||
if (!is_int($date)) return ['ok'=>false,'error'=>'«date» header could not be converted to a unix timestamp'];
|
||||
$reset=@strtotime($aaheaders['x-ratelimit-reset']);
|
||||
|
|
Loading…
Reference in a new issue