php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #15976 socket_get_status(...) returns nothing
Submitted: 2002-03-09 17:31 UTC Modified: 2002-04-12 22:12 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: sean at caedmon dot net Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.1.2 OS: Win32 (2000) AND Linux2.2
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: sean at caedmon dot net
New email:
PHP Version: OS:

 

 [2002-03-09 17:31 UTC] sean at caedmon dot net
socket_get_status is supposed to return an associative array, it _always_ returns null for me. No array, no object, no string print_r(socket_get_status($verifiedSocketResource)) prints nothing.

I've tried this on two separate 4.1.x installs. The php4win version (4.1.1) and the Debian Unstable version (4.1.2 -- CGI).

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-03-09 17:34 UTC] sean at caedmon dot net
Also note: This is a listening socket (host / server / whatever) -- ie, not created with fsockopen; created with socket_create, socket_bind, socket_listen, socket_accept. There's a note in the manual about this not working properly, but I didn't see it in the bug DB.
 [2002-03-12 21:00 UTC] sean at caedmon dot net
It's a non-blocking socket, if that helps

S
 [2002-03-12 21:44 UTC] sean at caedmon dot net
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
 [2002-03-12 21:48 UTC] sean at caedmon dot net
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-18 15:26 UTC] wez@php.net
Could you try this with a current CVS snapshot?
The file/socket layer has been rewritten so this
should be fixed.

 [2002-03-18 15:27 UTC] wez@php.net
PS: Go for the most recent snap you can find, or better
yet, actually check it out from CVS.
--Wez. :-)
 [2002-03-19 13:24 UTC] sean at caedmon dot net
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-04-12 22:12 UTC] wez@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Sep 19 13:01:27 2024 UTC