function socketApi() { error_reporting(E_ALL); set_time_limit(0); $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); if ($socket === false) { $error_code = socket_last_error(); $error_msg = socket_strerror($error_code); die("Couldn't create socket: [$error_code] $error_msg"); } $result = socket_connect($socket, $this->ip, $this->port); if (!$result) { $this->errorStr = "socket_connect() Failed.\nReason: ($result) " . socket_strerror($result) . "\n"; return $this->errorStr; } $in = $this->bodyTit . $this->bodyXml; if (!socket_write($socket, $in, strlen($in))) { $this->errorStr = "socket_write() Failed: reason: " . socket_strerror($socket) . "\n"; return $this->errorStr; } while ($out = @socket_read($socket, 8192)) { $this->outTradingType = substr($out, 87, 6); $this->outSubject = trim(substr($out, 93, 100)); $this->outBodyTit = substr($out, 0, 222); if ($this->outTradingType == '000000') { $this->outBodyXml = substr($out, 222); $this->outXmlArr = self::xmlToArray($this->outBodyXml); } else { $this->errCode = $this->outTradingType; $this->errStr = $this->outSubject; return $this->errStr; } } socket_close($socket); return $this->errStr; }