Result - 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.
Result of php executing
Full code of Result.php
- <?php
- class A {tet
- protected function doSomeIncr($id, $group)
- {
- if($id != null)
- {
- if($group === null)
- $group = 'default';
- if( $group == 'default' )
- $connection = Yii::$app->redisDefault;
- elseif($group == 'redis')
- $connection = Yii::$app->redis;
- else
- $connection = Yii::$app->redisDefault;
- $value = $connection->get('key:'.time().':'.$group.':'.$id);
- if( $value < 100 )
- {
- $val = $connection->incr('key:'.time().':'.$group.':'.$id);
- if( $val == 1 )
- $this->$connection->expire('key:'.time().':'.$group.':'.$id, 100);
- $result = true;
- }
- else
- {
- $trafficPercent = 50;
- if($trafficPercent < rand(0, 100))
- {
- $result = false;
- }
- else
- {
- $val = $connection->incr('key:'.time().':'.$group.':'.$id);
- if( $val == 1 )
- $this->$connection->expire('key:'.time().':'.$group.':'.$id, 100);
- $result = true;
- }
- }
- }
- else
- $result = false;
- return $result;
- }
- }