コード例 #1
0
ファイル: demo-multi.php プロジェクト: valmat/MC_Counter
require './src/class.memstore.php';
require './src/class.redis.php';
function microtime_float()
{
    list($usec, $sec) = explode(" ", microtime());
    return (double) $usec + (double) $sec;
}
################################################################################
$time_start = microtime_float();
$CNT = 200;
$mode = 'mg';
if ('s' == $mode) {
    for ($i = 0; $i < $CNT; $i++) {
        if (mt_rand(0, 1)) {
            $cnt = new Counter('AnySlot', $i);
            echo '<h2>' . $cnt->increment() . '</h2>';
        }
    }
}
if ('g' == $mode) {
    $rez = array();
    for ($i = 1; $i <= $CNT; $i++) {
        $cnt = new Counter('AnySlot', $i);
        $rez[$i] = $cnt->get();
    }
    echo "<hr><pre>";
    var_export($rez);
    echo '</pre><hr>';
}
if ('mg' == $mode) {
    $keys = array_keys(array_fill(1, $CNT, 1));
コード例 #2
0
ファイル: Router.php プロジェクト: AmbreB/ExercicesSimplon
 public function incrementCounter($id)
 {
     $C = new Counter();
     $newvalue = $C->increment($id);
     echo json_encode(['id' => $id, 'count' => $newvalue]);
 }
コード例 #3
0
 public function testShouldDispatchEventFromOtherSubscription()
 {
     $logger = new Logger();
     $this->app->subscribe('payment.failure', 'logger', function (Application $app) use($logger) {
         $logger->log('Payment failure');
         $app->dispatch('payment.attempt');
     });
     $counter = new Counter();
     $this->app->subscribe('payment.attempt', 'paymentCounter', function () use($counter) {
         $counter->increment();
     });
     $this->app->dispatch('payment.failure');
     $this->assertEquals(1, $counter->total());
 }
コード例 #4
0
ファイル: index.php プロジェクト: yinm/yinm.github.io
<?php

require_once './Counter.php';
$counter = new Counter();
$counter->increment();
$cnt = $counter->get();
?>

<html>
<head>
    <title>PHP講座 - トップページ</title>
</head>
<body>
<h1>PHP講座</h1>
<p>あなたは<?php 
echo $cnt;
?>
番目の訪問者です</p>
</body>
</html>
コード例 #5
0
ファイル: DispatcherTest.php プロジェクト: php-lab/event
 public function testShouldNotifyListenersByPriorities()
 {
     $logger = new Logger();
     $this->app->subscribe('payment.failure', 'logger', function () use($logger) {
         $logger->log('Payment failure');
         return ['stop' => true];
     }, 10);
     $counter = new Counter();
     $this->app->subscribe('payment.failure', 'errorCounter', function () use($counter) {
         $counter->increment();
     }, 20);
     $this->app->dispatch('payment.failure');
     $this->assertEquals(1, $counter->total());
 }