I am connecting my website to a server having an application in VB6. I connect to an IP on a specified port using PHP. My code is as follows:
public static function hello()
{
static::$version = Config::get('socket.version');
static::$user = Config::get('socket.user');
static::$pwd = Config::get('socket.password');
$xmlstr = '<?xml version="1.0"?>';
$xmlstr .= '<HelloRequest version="' . static::$version . '" user="' . static::$user . '" pwd="' . static::$pwd . '" />';
//$xmlstr = '|'.strlen($xmlstr).'|'.$xmlstr; // Appending Length
return static::runRequest($xmlstr);
}
and it calls runRequest($xmlstr) method in the same class:
public static function runRequest($request)
{
static::$address = Config::get('socket.address');
static::$port = Config::get('socket.port');
static::$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if (!static::$socket) {
return (object) array(
'error' => true,
'message' => "socket_create() failed: reason: " . socket_strerror(socket_last_error())
);
}
socket_set_option(static::$socket, SOL_SOCKET, SO_SNDTIMEO, array('sec' => 5, 'usec' => 0));
$result = socket_connect(static::$socket, static::$address, static::$port);
if (!$result) {
static::close();
return (object) array(
'error' => true,
'message' => "socket_connect() failed. Reason: ($result) " . socket_strerror(socket_last_error(static::$socket))
);
}
$bytes = socket_send(static::$socket, $request, strlen($request), 0);
if ($bytes > 0) {
$buf = " ";
$totalBytes = 0;
$outbuf = "";
$maxlen = 4096;
$loopcnt = 0;
$maxloops = 100;
while (true) {
$receivedBytes = socket_recv(static::$socket, $buf, $maxlen, 0);
if ($receivedBytes > 0) {
$buf = str_replace("&", "&", $buf);
$outbuf .= $buf;
$totalBytes += $receivedBytes;
if(strrpos($outbuf, "\r\n") == true)
break;
}
$loopcnt++;
}
$outbuf = str_replace("\r\n", "", $outbuf);
socket_close(static::$socket);
return (object) array(
'error' => false,
'message' => $outbuf
);
}
socket_close(static::$socket);
return (object) array(
'error' => true,
'message' => 'Something went wrong. Please try again.'
);
}
PROBLEM IS THAT THE CODE STUCKS at: $receivedBytes = socket_recv(static::$socket, $buf, $maxlen, 0);
and returns 500 internal Server Error in Page Title and Request Time out on Page:
Request Timeout
This request takes too long to process, it is timed out by the server. If it should not be timed out, please contact administrator of this web site to increase 'Connection Timeout'.
Any Clue on it what might be wrong. Username/Paswords, IP and ports are correct, tested using putty.
We are using litespeed server (not apache). Here are the logs for the event:
2015-06-15 17:46:35.201 [INFO] [ip.address.removed:62539:HTTP2-1] Connection idle time: 121 while in state: 6 watching for event: 25,close! 2015-06-15 17:46:35.201 [NOTICE] [ip.address.removed:62539:HTTP2-1] Content len: 0, Request line: 'GET /socket/hello HTTP/1.1' 2015-06-15 17:46:35.201 [NOTICE] [ip.address.removed:62539:HTTP2-1] Redirect: #1, URL: /index.php/socket/hello 2015-06-15 17:46:35.201 [INFO] [ip.address.removed:62539:HTTP2-1] HttpExtConnector state: 8, request body sent: 0, response body size: -2, response body sent:0, left in buffer: 0, attempts: 0. 2015-06-15 17:46:35.201 [INFO] [ip.address.removed:62539:HTTP2-1] Lsapi connection state: 3, watching event: 25, respState: 1, m_iTotalPending:0, m_iPacketLeft:0, m_iCurRespHeader:791624304, req sent for 121 seconds,Total processing time: 121. 2015-06-15 17:46:35.201 [INFO] [ip.address.removed:62539:HTTP2-1] Abort request processing by PID:4736, kill: 1, begin time: 121, sent time: 121, req processed: 0