PHPDaemon\Clients\Mongo\Pool::requestCbProducer PHP Method

requestCbProducer() protected method

protected requestCbProducer ( integer $opcode, string $data, boolean $reply = false, callable $sentcb = null ) : callable
$opcode integer Opcode (see constants above)
$data string Data
$reply boolean Is an answer expected?
$sentcb callable Sent callback
return callable
    protected function requestCbProducer($opcode, $data, $reply = false, $sentcb = null)
    {
        return function ($conn) use($opcode, $data, $reply, $sentcb) {
            if (!$conn || $conn->isFinished()) {
                if ($this->finished) {
                    if ($sentcb !== null) {
                        $sentcb(false);
                    }
                } else {
                    $this->getConnectionRR($this->requestCbProducer($opcode, $data, $reply, $sentcb));
                }
                return;
            }
            $reqId = ++$conn->lastReqId;
            $this->lastRequestConnection = $conn;
            $conn->write(pack('VVVV', mb_orig_strlen($data) + 16, $reqId, 0, $opcode));
            $conn->write($data);
            if ($reply) {
                $conn->setFree(false);
            }
            if ($sentcb !== null) {
                $sentcb($conn, $reqId);
            }
        };
    }