ID: 43731 Updated by: [EMAIL PROTECTED] Reported By: uth3r_p3ndrag0n at yahoo dot com -Status: Open +Status: Bogus Bug Type: Sockets related Operating System: Linux, Debian Etch 4.0r1 PHP Version: 5.2.5 New Comment:
php://stdin is not a socket. Previous Comments: ------------------------------------------------------------------------ [2008-01-02 19:58:17] uth3r_p3ndrag0n at yahoo dot com Description: ------------ When running a php script via inetd, I cannot get the remote address due to socket_getpeername's parameter type. There seems no way to treat the stdin as a socket for this function. The C system call, getpeerbyname (in <sys/socket.h>) takes a file descriptor. When called by inetd, passing 0 (or stdin) returns the peer information of the socket which is mapped to the stdin of the running process. There may not be anyway to work around this considering the way sockets were designed in php. I tried opening php://stdin and using the resource returned, but that isn't a Socket resource. I would have expected to be able get a socket resource of stdin via 'fsockopen("php://stdin")', as specified in http://www.php.net/manual/en/wrappers.php.php, but despite it's url style naming, fsockopen returns 'Unable to find the socket transport "php"' Reproduce code: --------------- $stdin = fopen('php://stdin'); socket_getpeername($stdin, $addr, $port); OR $stdin = fsockopen('php://stdin'); socket_getpeername($stdin, $addr, $port); Expected result: ---------------- $addr and $port should have been populated with the ip address and port #. Actual result: -------------- Warning: socket_getpeername(): supplied resource is not a valid Socket resource in [script name] on line X OR Warning: fsockopen(): unable to connect to php://stdin:-1 (Unable to find the socket transport "php" - did you forget to enable it when you configured PHP?) in [script_name] on line X ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=43731&edit=1