|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43731 socket_getpeername: cannot use on stdin with inetd
Submitted: 2008-01-02 19:58 UTC Modified: 2008-11-04 21:06 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: uth3r_p3ndrag0n at yahoo dot com Assigned:
Status: Closed Package: Sockets related
PHP Version: 5.2.5 OS: Linux, Debian Etch 4.0r1
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: uth3r_p3ndrag0n at yahoo dot com
New email:
PHP Version: OS:


 [2008-01-02 19:58 UTC] uth3r_p3ndrag0n at yahoo dot com
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, 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);


    $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


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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-11-04 21:06 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

Fixed, now stream_socket_get_name(STDIN, true) should work in the cli.
 [2012-01-06 22:12 UTC] edo888 at gmail dot com
Doesn't seem to work for me.

# php -v
PHP 5.3.8 with Suhosin-Patch (cli) (built: Dec 23 2011 18:46:04)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies

# php -r "fsockopen('php://stdin');"

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 Command line code on line 1
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu Aug 18 02:05:45 2022 UTC