<?php
$count = 0;
$pool = new SplQueue();
$server = new Swoole\Http\Server('127.0.0.1', 9501, SWOOLE_BASE);

$server->on('Request', function($request, $response) use(&$count, $pool) {
    if (count($pool) == 0) {
        $redis = new Swoole\Coroutine\Redis();
        $res = $redis->connect('127.0.0.1', 6379);
        if ($res == false) {
            $response->end("redis connect fail!");
            return;
        }
        $pool->enqueue($redis);
    }
    $redis = $pool->dequeue();
    $count ++;
    $ret = $redis->set('key', 'value');
    $response->end("swoole response is ok, count = $count, result=" . var_export($ret, true));
    $pool->enqueue($redis);
});

$server->start();

<?php
$count = 0;
$pool = new SplQueue();
$server = new Swoole\Http\Server('127.0.0.1', 9501, SWOOLE_BASE);

$server->on('Request', function($request, $response) use(&$count, $pool) {
    if (count($pool) == 0) {
        $redis = new Swoole\Coroutine\Redis();
        $res = $redis->connect('127.0.0.1', 6379);
        if ($res == false) {
            $response->end("redis connect fail!");
            return;
        }
        $pool->push($redis);
    }
    $redis = $pool->pop();
    $count ++;
    $ret = $redis->set('key', 'value');
    $response->end("swoole response is ok, count = $count, result=" . var_export($ret, true));
    $pool->push($redis);
});

$server->start();

--- 
+++ 
@@ -11,13 +11,13 @@
             $response->end("redis connect fail!");
             return;
         }
-        $pool->push($redis);
+        $pool->enqueue($redis);
     }
-    $redis = $pool->pop();
+    $redis = $pool->dequeue();
     $count ++;
     $ret = $redis->set('key', 'value');
     $response->end("swoole response is ok, count = $count, result=" . var_export($ret, true));
-    $pool->push($redis);
+    $pool->enqueue($redis);
 });
 
 $server->start();
Fix unexpected swoole sever crash on high concurrency operation

`SplQueue` is operated using `enqueue()` and `dequeue()` not with `push()` and `pop()` which is for `Stack`.

`SplQueue` is a `FIFO`, but use of `push/pop` turns it into `Stack` which is `LIFO`, this has caused numerous disconnections that resulted into a swoole server crash.

By fixing this, disconnection from database server does not cause server crash anymore.

Ref.

[SplQueue dequeue](http://php.net/manual/en/splqueue.dequeue.php)
[SplQueue enqueue](http://php.net/manual/en/splqueue.enqueue.php)