/** * send a command to R * @param int $command command code * @param string $v command contents */ private function command($command, $v) { $pkt = _rserve_make_packet($command, $v); socket_send($this->socket, $pkt, strlen($pkt), 0); // get response $n = socket_recv($this->socket, $buf, 16, 0); if ($n != 16) { return FALSE; } $len = int32($buf, 4); $ltg = $len; while ($ltg > 0) { $n = socket_recv($this->socket, $b2, $ltg, 0); if ($n > 0) { $buf .= $b2; unset($b2); $ltg -= $n; } else { break; } } $res = int32($buf); return array('code' => $res, 'is_error' => ($res & 15) != 1, 'error' => $res >> 24 & 127, 'contents' => $buf); }
/** * send a command to Rserve * @param int $command command code * @param string $data data packets * @return int if $async, TRUE */ protected function sendCommand($command, $data) { $pkt = _rserve_make_packet($command, $data); if ($this->debug) { $this->debugPacket($pkt); } socket_send($this->socket, $pkt, strlen($pkt), 0); if ($this->async) { return TRUE; } // get response return $this->getResponse(); }