qwe - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of qwe.php

  1. <?php
  2. class A {
  3.         protected function doSomeIncr($id, $group)
  4.     {
  5.         if($id != null)
  6.                 {
  7.                         if($group === null)
  8.                                 $group = 'default';
  9.                        
  10.                         if( $group == 'default' )
  11.                                 $connection = Yii::$app->redisDefault;
  12.                         elseif($group == 'redis')
  13.                                 $connection = Yii::$app->redis;
  14.                         else
  15.                                 $connection = Yii::$app->redisDefault;
  16.                        
  17.                         $value = $connection->get('key:'.time().':'.$group.':'.$id);
  18.                        
  19.                         if( $value < 100 )
  20.                         {
  21.                                 $val = $connection->incr('key:'.time().':'.$group.':'.$id);
  22.  
  23.                                 if( $val == 1 )
  24.                                         $this->$connection->expire('key:'.time().':'.$group.':'.$id, 100);
  25.                                
  26.                                 $result = true;
  27.                         }
  28.                         else
  29.                         {
  30.                                 $trafficPercent = 50;
  31.                                 if($trafficPercent < rand(0, 100))
  32.                                 {
  33.                                         $result = false;
  34.                                 }
  35.                                 else
  36.                                 {
  37.                                         $val = $connection->incr('key:'.time().':'.$group.':'.$id);
  38.  
  39.                                         if( $val == 1 )
  40.                                                 $this->$connection->expire('key:'.time().':'.$group.':'.$id, 100);
  41.                                        
  42.                                         $result = true;
  43.                                 }
  44.                         }
  45.                 }
  46.                 else
  47.                         $result = false;
  48.  
  49.         return $result;
  50.     }
  51. }
  52.  
  53.  
File Description
  • qwe
  • PHP Code
  • 18 May-2023
  • 1009 Bytes
You can Share it: