OESocketServer and PHP / Perl (OpenInsight 32-Bit)
At 19 JUN 2008 10:43:14AM Stefano Cavaglieri wrote:
Well, I'm back on this topic after some very extensive research and unfortunately no good results. I tried to implement the oecgi2.php AND the oecgi2.pl scripts according to Bob Carten's info.
Both scripts connect to the OESocketServer, and I also get some data back from my procedures, but this only works properly if the data coming back is less then, around, 4k !!! (i.e. INET_TRACE for instance will work okay).
Looking at the OESocketServer window, which is running in debug mode, I can see my data - always - but if the request brings back more than the 4k, an error is added "Error waiting for response: An existing connection was forcibly closed by the remote host" - and the output in the browser is truncated.
Same result with PHP and with Perl - does it mean that the error's in the OESocketServer somewhere?
Best,
Stefano
At 19 JUN 2008 01:54PM Bob Carten wrote:
Hi Stefano,
I bet the problem is related to unicode characters in the data.
If you Base64Encode the response in OI, then base64Decode in php do you have success? If not, please email me a copy of what you are trying to return, I will test it.
- Bob
At 19 JUN 2008 06:54PM David Goddard wrote:
G'day Stefano,
FYI - I'm sending/receiving 2mb+ data to/from oecgi2.exe/oesocketserver with no problems (OI v8.03).
I'm using javascript and prototypejs framework.
Types of data include:
text - xml, html and json
images - jpg, tiff and bmp
pdf's
word and excel docs
I don't have much experience with php and perl. But would enjoy to hear the results from Bob C.
Dave G
At 20 JUN 2008 03:48AM Stefano Cavaglieri wrote:
Hi David,
As long as I use oecgi2.exe I do not have any problems at all (same as you wrote), I only see those issues when trying to make the same calls using PHP or Perl.
Stefano
At 20 JUN 2008 04:45AM Stefano Cavaglieri wrote:
Hi Bob,
Don't think the problem is related to unicode characters in the data, this specific OI application is not in UTF8 character mode.
Just to make sure, I also tried to Base64Encode the response in OI, then base64_decode in PHP - same result. Try this quick and dirty procedure:
compile function Inet_Test(Request)
begin condition
Pre:
Post:
end condition
*
* Name : Inet_Test
* Description: Generates some data for HTTP request
*
* Parameters:
* Request in – HTTP request
* ret out – HTML script with test data
*
$insert Inet_Equates
html="
for Z=1 to 178
html := "This is testing line ":Z:\0A\next Z
return html
On my workstation (Windows XP Pro SP3, Apache 2.2.8, PHP 5.2.6) this runs with no errors. Now increase the loop counter to 1000 and retry it… the output gets truncated and an error message (see my previuos message) drops into the OESocketServer debug window.
Can you reproduce that? Thanks in advance for all hints.
Stefano
At 20 JUN 2008 01:17PM Bob Carten wrote:
Thanks Stefano, I'll work with this, let you know
At 21 JUL 2008 11:02AM Bob Carten wrote:
Stefano
I duplicated your issue with truncated responses from the OECGI2.PHP example script. The problem was in my php script. I changed the script to read from OI in 2K chunks rather than one large blob.
I am able to use your example program to return thousands of lines.
The revised script is posted below.
Disclaimers
1. I am not a php programmer, I am sure that the script can be improved. Use at your own risk.
2. When IIS passes a script to an interpreter, IIS alters the information sent to RUN_OECGI_REQUEST so that it does not run.
If you look at the php script it calls RUN_MYCGI_REQUEST rather than RUN_OECGI_REQUEST. RUN_MYCGI_REQUEST is program which reformats the request for RUN_OECGI_REQUEST. A copy of RUN_MYCGI_REQUEST appears below.
Note: It is possible to configure IIS so that scripts with .CGI as an extension will call OECGI2.
If you use it with OECGI/OECGI2 then you need to modify the registry settings to call RUN_MYCGI_REQUEST
When you do that, then www.myserver/mysite/myproc.cgi will call INET_MYPROC
pre.code {
background-color: #E5E5E5;border: 1px solid #000000;width: 640px;padding: 5px;font-family: courier, verdana, arial, serif;margin: 0px 10px auto;}
OECGI2.PHP
<?php # OECGI2.PHP # OECGI quivalent in PHP # Note: # Php can run as isapi service on IIS, OECGI2.PHP can run inprocess # With TCPIP connection, have socketserver on a separate machine (OI appserver) # No need for Web server to have user rights on OI appserver # # 07-Jun-2007 rjc Created # 21-Jul-2008 rjc Fix for truncated messages - Receive response in 2k chunks error_reporting(E_ALL); $err="; $DELIM=chr(1); $cLOGIN =1"; $cLOGOFF =2"; $cCALL =3"; $cQuery =-1"; $cResetGentle =-2"; $cResetForce =-3"; $FM=chr(254); $UserName=MYAPP"; $Password="; $Database=MYUSER"; $ServerName="; $OiFuncName=RUN_MYCGI_REQUEST"; $address=gethostbyname('localhost'); $service_port=8089'; $request="; $response="; # GET or POST? $buffer="; if ($_REQUEST'REQUEST_METHOD' == "POST") { $buffer=fread(STDIN, $buffer, $_REQUEST'CONTENT_LENGTH'); }else { $buffer=$_REQUEST'QUERY_STRING'; } # Pass CGI params to OI. Note QUERY_STRING is first param $request=$_SERVER'QUERY_STRING' . $FM . $_REQUEST'PATH_INFO' . $FM . $_REQUEST'CONTENT_TYPE' . $FM . $_REQUEST'CONTENT_LENGTH' . $FM . $_SERVER'GATEWAY_INTERFACE' . $FM . $_REQUEST'HTTPS' . $FM . $_REQUEST'HTTP_ACCEPT' . $FM . $_REQUEST'HTTP_COOKIE' . $FM . "" . $FM . $_SERVER'HTTP_REFERER' . $FM . $_REQUEST'HTTP_USER_AGENT' . $FM . $_REQUEST'PATH_TRANSLATED' . $FM . $_REQUEST'REMOTE_ADDR' . $FM . $_REQUEST'REMOTE_HOST' . $FM . "" . $FM . $_REQUEST'REMOTE_USER' . $FM . $_REQUEST'REQUEST_METHOD' . $FM . $_REQUEST'SCRIPT_NAME' . $FM . $_REQUEST'SERVER_NAME' . $FM . $_REQUEST'SERVER_PORT' . $FM . $_REQUEST'SERVER_PROTOCOL' . $FM . $_REQUEST'SERVER_SOFTWARE' . $FM . ""; /* Create a TCP/IP socket. */ $socket=socket_create(AF_INET, SOCK_STREAM, SOL_TCP); if ($socket === false) { $err= "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n"; } #if ( $err=" ) { $result=socket_connect($socket, $address, $service_port); if ($result === false) { $err= "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n"; } #} # logon #if ( $err == "" ) { $sMsg=$cLOGIN . $DELIM . $UserName . $DELIM . $Password . $DELIM . $Database . $DELIM . "2" . $DELIM . $ServerName . $DELIM . $OiFuncName . $DELIM; $ret=SendMessage($socket, $sMsg); #} # Package the request in JD3 protocol #if ( $err == "" ) { $sMsg=$cCALL . $DELIM . $request . $DELIM; $response=SendMessage($socket, $sMsg); #} # Clean Up #if ( $err == "" ) { $sMsg= $cLOGOFF . $DELIM ; $ret=SendMessage($socket, $sMsg); socket_close($socket); #} # return response echo $response; function SendMessage($sock, $sMsg) { $buffer="; $ret="; # encode with 8 char length prefix $delim=chr(1); $mlen =strlen($sMsg); $diff=8 - strlen($mlen); $prefix=str_repeat('0', $diff) . $mlen; $encoded=$prefix . $sMsg; # Xmit, strip leading, trailing delims out of response socket_write($sock, $encoded, strlen($encoded)); $resultlen=socket_read($sock, 8); # 21-Jul-2008 rjc Fix for truncated messages - Receive response in 2k chunks $result="; $rcvlen=0; do { if (false == ($buffer=socket_read($sock, 2048))) { $result .= "socket_read() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n"; break 2; } $rcvlen += strlen($buffer); $result .= $buffer; $buffer="; } while ($rcvlen < $resultlen); return $result; } ?>RUN_MYCGI_REQUEST
function RUN_MYCGI_Request(Request, ProcErr) /* * Pre-process cgi requests when using IIS with .CGI extensions * * 15Feb2008 rjc Created */ Declare Function RUN_OECGI_REQUEST $insert Inet_equates cgi_extension=.CGI' default_page= '/login' * Trim off the CGI extension path_info=Request<PATH_INFO$> orig=path_info If path_info-4,4 _eqc cgi_extension then path_info-4,4=' end If path_info=" or path_info=/' Then path_info=default_page end * * run_oecgi_request expects path_info=/scriptname * IIS with cgi extension sets path_info differently ( /dir/scriptname instead Of /scriptname ) path_Info=/' : path_info-1,'B/' If path_info # orig then Request<PATH_INFO$>=path_info end return RUN_OECGI_REQUEST(Request, ProcErr)
At 25 JUL 2008 06:45AM Stefano Cavaglieri wrote:
Thanks a lot Bob.
Stefano