ID:               34851
 Updated by:       [EMAIL PROTECTED]
 Reported By:      khayll at motoros dot hu
-Status:           Open
+Status:           Feedback
 Bug Type:         Sockets related
 Operating System: win 2k3 server
 PHP Version:      4.4.0
 New Comment:

Well, that's because USEC are *microseconds*, not milliseconds.
Try to use sec=0 usec=5000000 instead.


Previous Comments:
------------------------------------------------------------------------

[2005-10-13 17:52:20] khayll at motoros dot hu

sorry I forgot a line from the code:

I also decreased the sec param to 1 because for me the remote host is
quite fast.

<?php

        $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
        socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec"=>1,
"usec"=>0));
        socket_connect($socket, "81.182.13.109", "502");

        $pdu = "";
        $pdu .= chr(0x03).chr(floor(16000 / 256)).chr(16000 %
256).chr(floor(10 / 256)).chr(10 % 256);

        $rand = mt_rand(1,65535); //generate random adu id
        $adu = "";
        $adu .= chr(floor($rand / 256)).chr($rand %
256).chr(0).chr(0).chr(floor(6 / 256)).chr(6 % 256).chr(1);
        
        $data = $adu.$pdu;

        socket_write($socket, $data, strlen($data));

        $result = socket_read($socket, 512, PHP_BINARY_READ);

        echo socket_strerror(socket_last_error());

        socket_shutdown($socket, 2);
        socket_close($socket);

?>

------------------------------------------------------------------------

[2005-10-13 17:41:05] khayll at motoros dot hu

And if I set sec=0 usec=500000 (or 5 for a shorter timeout) it hangs,
meaning to me, that usec has no effect.

------------------------------------------------------------------------

[2005-10-13 17:38:56] khayll at motoros dot hu

Actual: Script gives timeout error but it does not wait for 5 seconds
for the answer, as set in SO_RCVTIMEO.

Expeted: to wait max. 5 second for remote host to answer, but script
executes much faster. I tried to increase second to 500000 and then it
works ok.

------------------------------------------------------------------------

[2005-10-13 16:16:23] [EMAIL PROTECTED]

And actual/expected results please?

------------------------------------------------------------------------

[2005-10-13 14:36:01] khayll at motoros dot hu

<?php

        $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
        socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec"=>5,
"usec"=>0));
        socket_connect($socket, "81.182.13.109", "502");

        $pdu = "";
        $pdu .= chr(0x03).chr(floor(16000 / 256)).chr(16000 %
256).chr(floor(10 / 256)).chr(10 % 256);

        $rand = mt_rand(1,65535); //generate random adu id
        $adu = "";
        $adu .= chr(floor($rand / 256)).chr($rand %
256).chr(0).chr(0).chr(floor(6 / 256)).chr(6 % 256).chr(1);
        
        socket_write($socket, $data, strlen($data));

        $result = socket_read($socket, 512, PHP_BINARY_READ);

        echo socket_strerror(socket_last_error());

        socket_shutdown($socket, 2);
        socket_close($socket);

?>

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/34851

-- 
Edit this bug report at http://bugs.php.net/?id=34851&edit=1

Reply via email to