$connection->close(); return; } echo "auth ok\n"; global $onMessage; $connection->onMessage = $onMessage; $onMessage($connection, null); //ugly but just working }; // Emitted when new connection come $worker->onConnect = function ($connection) { echo "connected to redis\n"; global $redis_password; if ($redis_password) { $connection->send("AUTH {$redis_password}\n", true); } else { global $onLogin; $onLogin($connection, true); //no auth = success } }; $worker->onMessage = $onLogin; // Emitted when connection closed $worker->onClose = function ($connection) { echo "Server Closed Connection, stop this worker.\n"; //Master process will start a new worker process $connection->worker->stop(); }; // Run worker Worker::runAll();