@@ -19,7 +19,7 @@ public function doDecide(int $tracerId, string $operationName): SamplerResult
1919 {
2020 $ key = $ this ->generator ->generate ($ tracerId , $ operationName );
2121 $ ttl = max ((int )(1 / $ this ->rate + 1 ), 1 );
22- if (false !== ( $ current = apcu_add ($ key , sprintf ('%s:%d ' , time (), 1 ), $ ttl) )) {
22+ if (apcu_add ($ key , sprintf ('%s:%d ' , time (), 1 ), $ ttl )) {
2323 return new SamplerResult (
2424 true , 0x01 , [
2525 new SamplerTypeTag ('ratelimiting ' ),
@@ -30,15 +30,17 @@ public function doDecide(int $tracerId, string $operationName): SamplerResult
3030 );
3131 }
3232
33- while (true ) {
33+ $ retries = 0 ;
34+ while ($ retries < 5 ) {
3435 if (false === ($ current = apcu_fetch ($ key ))) {
3536 return $ this ->doDecide ($ tracerId , $ operationName );
3637 }
3738 list ($ timestamp , $ count ) = explode (': ' , $ current );
38- if ($ count / (time () - $ timestamp ) > $ this ->rate ) {
39+ if (( int ) $ count / (time () - ( int ) $ timestamp ) > $ this ->rate ) {
3940 return new SamplerResult (false , 0 );
4041 }
41- if (false === apcu_cas ($ key , $ current , sprintf ('%s:%d ' , $ timestamp , $ count + 1 ))) {
42+ if (false === apcu_cas ($ key , $ current , sprintf ('%s:%d ' , $ timestamp , (int )$ count + 1 ))) {
43+ $ retries ++;
4244 continue ;
4345 }
4446
0 commit comments