From:             [EMAIL PROTECTED]
Operating system: W2K
PHP version:      4.1.0
PHP Bug Type:     Sockets related
Bug description:  server RECV strange if using PHP clients

we've got a serious problem that we couldn't fix within a week even after
trying several options. So we very much appreciate ANY help.

We use PHP 4.1.0 on Windows 2000 server under IIS.

Situation: we are running socket-based servers that follow the
implementation recommendations found at http://tangentsoft.net/wskfaq/. The
problems encountered can be reproduced by using the "BasisServer" provided
at http://tangentsoft.net/wskfaq/examples/basics/basic-client.html.

Test1.

We use the fokkowing PHP-Script. Thereby we use the native socket-functions
introduced in PHP 4.1.0.

<?
 
 $port = 2222;
 $string = "P RegioTicket/Haltestellensuche@R 0@N Frankfurt@A 15@";
 
 $socket = socket_create (AF_INET, SOCK_STREAM, 0); 
 if ($socket < 0) 
 {
    echo "socket_create() failed: reason: ";
 } 
 else 
 {
    "socket_create() successful: ";
 }
 $ip = gethostbyname ('172.24.79.232'); 
 echo "&nbsp;Attempting to connect to '$ip' on port '$port'...";
 $result = socket_connect ($socket, $ip, $port);
 if ($result < 0) 
 {
    echo "socket_connect() failed.\nReason: ($result) " .
socket_strerror($result) . "\n";
 } 
 else 
 {
    echo "   OK.\n";    
 }
 $length =  strlen($string);
 
 echo "<br>Variable $" . $string . "$<BR>";
  
 $retcodew = socket_write ($socket, $string, $length);  
 $retcoder = socket_read ($socket, $var, 10);
  
echo "<br>Variable $" . $var . "$<BR>";
echo "return Code Write :" . $retcodew . "<br>";
echo "Return Code Read :" . $retcoder ;

?>

To follow the example debug the BasicServer.exe  (basic-server.cpp) or just
believe me <g>.

The server waits within ACCEPT. When the client sends data it RECEIVES this
data and SENDS it back as an echo. It cycles throught the rest of the loop,
ending in another RECEIVE. This RECEIVE returns "-1", which is recognized
as an socket error, finally leading into closing down the server. Unwanted
result.

Test2.

We use the following PHP-script. Thereby we use the classic style with
fsockopen, fputs, fgets, fsockclose.

<?php
        $anfrage = "P RegioTicket/Haltestellensuche@";
        $anfrage .= "R 0@";
        $anfrage .= "N Frankfurt@";
        $anfrage .= "A 15@";    
  echo "$anfrage <br>";
  
  $fp = fsockopen("172.24.79.232", 2222, &$errno, &$errstr, 10);
        if(!$fp)
        {
            $err = "error: $errstr ($errno)<br>";
            return $err;
        }
        else
        {
            $n = strlen($anfrage); // size of buffer for request
            //$str = sprintf("%08d%s", $n, $anfrage);
            fputs($fp, $anfrage);
                                                
                        echo "test nach puts()";
            $result = fgets($fp, 128);
            //get_selection($fp, $select);
            //socket_shutdown($fp, 1);
            fclose($fp);
            return $result;
        }          
?>

The server waits within ACCEPT. When the client sends data it RECEIVES this
data and SENDS it back as an echo. It cycles throught the rest of the loop,
ending in another RECEIVE. This RECEIVE waits indefinitely until some
timeout occurs. Unwanted result, the server is blocked.

Test3.

We use one of our good old REXX scripts and rxsock.dll.

The server waits within ACCEPT. When the client sends data it RECEIVES this
data and SENDS it back as an echo. It cycles throught the rest of the loop,
ending in another RECEIVE. This RECEIVE returns "0" which indicates that no
more data is available, the server closes the connection, recycles itself
into the ACCEPT statement again and waits for the next connection request.
We consider this to be the expected result, being comaptible to our own
C++-clients and the examples we found in the Internet.

So our question is, why the results are different when using PHP. Maybe we
just need to know how to inplement that in a better way using PHP. But as
we already spent some considerable time with it, we think, that the
inplementation within PHP (both) might need some improvement. But maybe PHP
just needs server that follow some rules of a protocol. If so, where can we
find specifications  for this?
-- 
Edit bug report at: http://bugs.php.net/?id=14806&edit=1


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to