php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #38739 stream_socket_server should not require a port
Submitted: 2006-09-07 09:33 UTC Modified: 2018-05-05 18:36 UTC
Votes:3
Avg. Score:3.7 ± 1.2
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:2 (66.7%)
From: magicaltux at ookoo dot org Assigned:
Status: Wont fix Package: *General Issues
PHP Version: 5.1.6 OS: *
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: magicaltux at ookoo dot org
New email:
PHP Version: OS:

 

 [2006-09-07 09:33 UTC] magicaltux at ookoo dot org
Description:
------------
When trying, for example, to do :

<?php
$socket = stream_socket_server('tcp://0.0.0.0', $errno, $errstr);
var_dump($errstr);
?>


We get the following output :
Warning: stream_socket_server(): unable to connect to tcp://0.0.0.0 (Failed to parse address "0.0.0.0") in /home/magicaltux/- on line 2
string(33) "Failed to parse address "0.0.0.0""

Expected result would be to have no port passed to bind, and thru having a random port allocated by the operating system (that we would later retrieve with stream_socket_get_name).

In socket_bind, the port is also optionnal.

It's still possible to get a random port by using ":0" but the no-port behaviour would be great too (and probably not too hard to implement).



Reproduce code:
---------------
<?php
$socket = stream_socket_server('tcp://0.0.0.0', $errno, $errstr);
var_dump($errstr);
?>

Expected result:
----------------
string(0) ""

Actual result:
--------------
Warning: stream_socket_server(): unable to connect to tcp://0.0.0.0 (Failed to parse address "0.0.0.0") in /home/magicaltux/- on line 2
string(33) "Failed to parse address "0.0.0.0""


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-09-15 12:52 UTC] cf0hay at gmail dot com
Use tcp://0.0.0.0:0 . Port 0 has a special meaning, which will result in exactly what you want.
 [2018-05-05 18:36 UTC] requinix@php.net
-Status: Open +Status: Wont fix -Package: Feature/Change Request +Package: *General Issues
 [2018-05-05 18:36 UTC] requinix@php.net
Old request is old.

Specifying port 0 is very much a standard practice.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 16 11:01:33 2025 UTC