- assigned_to: nobody --> tgueth
Sent to me by a user:
--------
Hi,
my name is Hans (i come from Germany)
I just evaluating the ODBC Socket Server - GREAT
SOFTWARE - THANKS :)
But i think there is a Bug when the ODBC Socket Server
received very fast
requests from one ore more clients on the "same time".
I use your PHP Client Class (class ODBCSocketServer)
If i just send ONE request to the Server it works very
fine, no
mather how
big is the xml result returned by the Server.
But if i send i.e.100 (or more) requests to the server
(i.e. in a
while($i<100 && $i++) ) the Server hangs after a few
$i (not
always but
most)
The Server hangs always after a few $i's when i call
the same
PHP-Script
twice in the same time.
(See the Example Code, attached in this mail)
I've read the FAQ
(http://odbcsock.sourceforge.net/faq.html)
but nothink
there about this issue, now im not shure where's the
Problem - winsock or
ODBC Socket Server.
Perhaps you know wheres the Problem
Thank you
Hans :)
Tested with:
Client:
Linux(Red-Hat) Kernel 2.4
PHP 4.2 (command line & trought Apache's (1.3.26) PHP
Modul)
Windows XP (full Updated from M$ Homepage)
Windows PHP 4.2 (command line)
ODBC Socket Server:
Windows XP (full Updated from M$ Homepage)
Database:
Newest Stable Windows MySql from mysql.com
ODBC Driver:
newest MyOdbc (stable) from mysql.com
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN" "http://www.w3.org/TR/REC-
html40/loose.dtd">
<HTML lang="en">
<HEAD>
<TITLE>PHP&nbsp;Test</TITLE>
<META name="author" content="TeamFXML">
<META name="copyright" content="Team FXML">
<META name="description" content="This page
description.">
<META name="keywords" content="insert, your, keywords">
</HEAD>
<BODY>
<?
//This is the ODBC Socket Server class PHP client class
with sample usage
// at bottom.
// (c) 1999 Team FXML
// Released into the public domain for version 0.90 of
ODBC
Socket Server
// http://odbc.linuxbox.com/
class ODBCSocketServer {
var $sHostName; //name of the host to connect to
var $nPort; //port to connect to
var $sConnectionString; //connection
string to use
//function to parse the SQL
function ExecSQL($sSQL) {
$fToOpen = fsockopen($this-
>sHostName, $this->nPort, &$errno, &$errstr, 30);
if (!$fToOpen)
{
//contruct error
string to return
$sReturn = "<?
xml version=\&quot;1.0\&quot;?>\r\n<result
state=\&quot;failure\&quot;>\r\n<error>$errstr</error>\r\n</result>\r\n";
}
else
{
//construct XML
to send
//search and
replace HTML chars in SQL first
$sSQL =
HTMLSpecialChars($sSQL);
$sSend = "<?
xml version=\&quot;1.0\&quot;?
>\r\n<request>\r\n<connectionstring>$this-
>sConnectionString</connectionstring>\r\n<sql>$sSQL</sql>
\r\n</request>\r\n";
//write request
fputs($fToOpen,
$sSend);
//now read
response
while (!feof
($fToOpen))
{
$sReturn = $sReturn . fgets($fToOpen, 128);
}
fclose($fToOpen);
}
return $sReturn;
}
}//class
//Here is the code that uses this class. First we
create the class
$oTest = new ODBCSocketServer;
//Set the Hostname, port, and connection string
$oTest->sHostName = "192.168.146.9";
$oTest->nPort = 9628;
#$oTest->sConnectionString
= "DSN=pubs;UID=jsmith;PWD=XXXX;";
$oTest->sConnectionString = "DSN=sal;";
//now exec the SQL
set_time_limit(0);
# On Windows, the Server hangs after ~ $i>50
# On Linux, the Server hangs when this Script will
called twice at the same time
for($i=0;$i<1000;$i++)
{
$oTest->ExecSQL
("SELECT count(*) FROM infotable");#1 row in table
echo $i."<br>\n";
flush();
}
exit;
//now format and print the results.
Subsititute in
your code here!
//We will use the PHP XML Parser module to
parse the result :)
//to use the parser, remember to compile PHP
with the --with-xml option
//see the PHP manual for more info and specific
examples
//For this example, we will print the results
in table
form
//and then print the raw XML string
//Here will be the XML handlers we will use
//Handler for starting elements
function startElement($parser, $name, $attribs)
{
if (strtolower($name) == "row")
{
//handler for the row element
print "<tr>";
}
if (strtolower($name) == "column")
{
//handler for the column
print "<td>";
}
if (strtolower($name) == "error")
{
//handler for the error
print "<tr><td>";
}
if (strtolower($name) == "result")
{
print "Table of Results:
<br><table border=1>";
}
}
//handler for the end of elements
function endElement($parser, $name)
{
if (strtolower($name) == "row")
{
//handler for the row element
print "</tr>";
}
if (strtolower($name) == "column")
{
//handler for the column
print "</td>";
}
if (strtolower($name) == "error")
{
//handler for the error
print "</td></tr>";
}
if (strtolower($name) == "result")
{
print "</table> <br>End Of
Results<br>";
}
}
//handler for character data
function characterData($parser, $data)
{
print "$data";
}
//parse the XML
$xml_parser = xml_parser_create();
xml_set_element_handler
($xml_parser, "startElement", "endElement");
xml_set_character_data_handler
($xml_parser, "characterData");
if (!xml_parse($xml_parser, $sResult)) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code
($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
else
{
echo("Successful XML parse. ");
}
print "Raw data results: <br>";
xml_parser_free($xml_parser);
$sResult = HtmlSpecialChars($sResult);
echo("<pre>");
echo($sResult);
echo("</pre>");
?>
</BODY>
</HTML>