Hello all,
I am diving into the relm of Sockets. Not by choice but I need to make it work.
This script does work but takes forever to give me the result. Do I have to set a timelimit or something?
<?php
error_reporting(E_ALL);
@ini_set('display_errors', '1');
echo 'Test Script';
$sale ='
<TRANSACTION>
<FUNCTION_TYPE>PAYMENT</FUNCTION_TYPE>
<COMMAND>SALE</COMMAND>
<PAYMENT_TYPE>CREDIT</PAYMENT_TYPE>
<ACCT_NUM>5439750001500206</ACCT_NUM>
<EXP_MONTH>12</EXP_MONTH>
<EXP_YEAR>08</EXP_YEAR>
<CARDHOLDER>John Doe</CARDHOLDER>
<CUSTOMER_ZIP>85284</CUSTOMER_ZIP>
<CUSTOMER_STREET>8320 Main Street</CUSTOMER_STREET>
<TRANS_AMOUNT>1.00</TRANS_AMOUNT>
<INVOICE>123456789012345</INVOICE>
<CLIENT_ID>100010001</CLIENT_ID>
<USER_ID>MANAGER</USER_ID>
<USER_PW>test</USER_PW>
</TRANSACTION>';
// where is the socket server?
$host="127.0.0.1";
$port = 5012;
$EOL = "\015\012";
// open a client connection
$fp = fsockopen ($host, $port, $errno, $errstr);
if (!$fp)
{
$result = "Error: could not open socket connection";
}
else
{
// get the welcome message
fgets ($fp, 1024);
// write the user string to the socket
fputs ($fp, $sale);
// get the result
$result = fgets ($fp, 1024);
// close the connection
fputs ($fp, "..".$EOL);
fclose ($fp);
// now print it to the browser
}
?>
Server said: <b><? echo $result; ?></b>
<?
echo '<br><br>Done!';
?>
The result should be XML but comes out looking like this:
Rita TestServer said: NOT_PROCESSED310026Configuration error: Incorrect password for user MANAGERERROR
If anyone can point me towards some better info on fsockopen I would love it. This is driving me nuts. The software we are connecting to is written in Java so we need to connect via a socket on port 5012