|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #75367 socket_select with STDIN on linux
Submitted: 2017-10-12 17:06 UTC Modified: 2017-10-12 19:09 UTC
From: divinity76 at gmail dot com Assigned:
Status: Wont fix Package: Sockets related
PHP Version: 7.0.24 OS: Debian 10, kernel 4.12.13
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
22 - 17 = ?
Subscribe to this entry?

 [2017-10-12 17:06 UTC] divinity76 at gmail dot com
socket_select should be able to listen to STDIN on linux, because it could be useful, and the underlying select() call is fully capable of doing it. i was recently in a situation where i needed to listen to changes both in a bunch of socket_accept'ed sockets, and STDIN at the same time, but socket_select doesn't accept STDIN in the $read array.. at least on linux, that shouldn't be a problem. 

Test script:
const PORT=9999;
$srv = socket_create ( AF_INET, SOCK_STREAM, SOL_TCP );
socket_bind ( $srv, "0", PORT );
socket_listen ( $srv );
$unused = array ();
$read = array (
while ( false !== socket_select ( $read, $unused, $unused, NULL ) ) {
	die("detected something");

Expected result:
it should detect activity on STDIN

Actual result:
PHP Warning:  socket_select(): supplied resource is not a valid Socket resource in /plain.php on line 11
PHP Stack trace:
PHP   1. {main}() /plain.php:0
PHP   2. socket_select() /plain.php:11


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-10-12 17:12 UTC]
-Status: Open +Status: Wont fix
 [2017-10-12 17:12 UTC]
STDIN is a stream resource, not a socket resource.

Use socket_import_stream(STDIN), if you wish to use socket_select() here. (Or, use socket_export_stream($srv) and use stream_select().)
 [2017-10-12 17:25 UTC] divinity76 at gmail dot com
@bwoebi neat trick in theory, but: 
$ php -r "socket_import_stream(STDIN);"
PHP Warning:  socket_import_stream(): cannot represent a stream of type STDIO as a Socket Descriptor in Command line code on line 1
PHP Stack trace:
PHP   1. {main}() Command line code:0
PHP   2. socket_import_stream() Command line code:1
 [2017-10-12 19:09 UTC]
Well, then you need to use socket_export_stream() on $srv if you want to use both in conjunction with stream_select().
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Dec 06 05:01:28 2023 UTC