ID:               15976
 Updated by:       [EMAIL PROTECTED]
 Reported By:      [EMAIL PROTECTED]
-Status:           Feedback
+Status:           Closed
-Bug Type:         Sockets related
+Bug Type:         Documentation problem
 Operating System: Win32 (2000) AND Linux2.2
 PHP Version:      4.1.2
 New Comment:

socket_get_status does not work with sockets from the sockets
extension.
I've updated the docs in CVS.
You need to use something like socket_select() to check
the socket status.


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

[2002-03-19 13:24:25] [EMAIL PROTECTED]

CVS Date: 2002.03.18 (afternoon EST)
----
socket_get_status has a return value now, but it still is incorrect.
I'm wary of posting code here, because I don't want to present the
image of asking for support, but in fact, socket_get_status is not
returning a proper value.

socket_get_status now complains about invalid file-handle resource
(when the passed resource is a socket resource -- I haven't tried this
with an actual file resource (although, that would seem useless)). 

Attached is the code I used to determine this.

S
---
//sock2.php
ob_implicit_flush();

$ip   = "localhost";
$port = "10000";

$listenSock = socket_create(AF_INET, SOCK_STREAM, 0);
socket_set_nonblock($listenSock);
socket_bind($listenSock, $ip, $port);
socket_listen($listenSock, 0);

$connected = false;

while (!$connected) {
    $msgSock = @socket_accept($listenSock);
    $connected = is_resource($msgSock);
}

echo "connected...\n";
socket_set_nonblock($msgSock);

for($i=1; $i<=300; $i++) {              // ~5 minutes
    socket_write($msgSock, ".", 1);     // send ".";
    echo ".";
    $status = socket_get_status($listenSock);
    print_r($status);
    
    sleep(1);
}
/*
note: to get the code to break out of the while loop, connect to
localhost on port 10000 (nc[or telnet] localhost 10000) in another
terminal.
*/
---
Here is my terminal log (terminal of the executing sock2.php):
---
sean@adnagaporp:~/php-dev/php4$ ./php -q
~/httpd/site/dev/sockets/sock2.php
connected...
.<br />
<b>Warning</b>:  socket_get_status(): supplied resource is not a valid
File-Handle resource in
<b>/home/sean/httpd/site/dev/sockets/sock2.php</b> on line <b>26</b><br
/>
.<br />
<b>Warning</b>:  socket_get_status(): supplied resource is not a valid
File-Handle resource in
<b>/home/sean/httpd/site/dev/sockets/sock2.php</b> on line <b>26</b><br
/>
.<br />
(etc...)
---
END

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

[2002-03-18 15:27:28] [EMAIL PROTECTED]

PS: Go for the most recent snap you can find, or better
yet, actually check it out from CVS.
--Wez. :-)

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

[2002-03-18 15:26:39] [EMAIL PROTECTED]

Could you try this with a current CVS snapshot?
The file/socket layer has been rewritten so this
should be fixed.


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

[2002-03-12 21:48:57] [EMAIL PROTECTED]

Oops. Regarding my previous comment:

line 968 reads "what = zend_fetch_resource(socket TSRMLS_CC, -1,
"File-Handle", &type, 1, le_socket);" in CVS, not what I posted
above...

S

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

[2002-03-12 21:44:49] [EMAIL PROTECTED]

Alright. So, here's what I've dug up so far:

file: [php]/ext/standard/file.c
line: 968
code: zend_fetch_resource(socket_arg TSRMLS_CC,-1,"Socket
-Handle",NULL,1,php_file_le_socket());

This always line returns false for a valid socket resource (I verified
the resource using `is_resource($sock)` and `get_resource_type($sock)`
for both my listen socket and my message socket.
get_resource_type($sock) returns "Socket".

So, when the next line (969), "ZEND_VERIFY_RESOURCE(what);" is called,
it determines that 'what' is false and calls RETURN_NULL;

I tried screwing with the args in zend_fetch_resource(...), but I don't
know the API well enough (and my C/C++ is more than rusty).

I hope someone takes a look at this soon, I currently have no way of
knowing the status of my sockets (I need to know when a client
disconnects -> eof )

S

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

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/15976

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

Reply via email to