php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34028 socket_create_listen doesn't listen on all interfaces
Submitted: 2005-08-07 20:43 UTC Modified: 2005-08-15 01:00 UTC
Votes:12
Avg. Score:2.7 ± 1.6
Reproduced:3 of 10 (30.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: alex at cedevices dot com Assigned:
Status: No Feedback Package: Sockets related
PHP Version: 5.0.4 OS: Windows 2000
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: alex at cedevices dot com
New email:
PHP Version: OS:

 

 [2005-08-07 20:43 UTC] alex at cedevices dot com
Description:
------------
Standard latest xampp setup (including PHP 5.0.4).
When using socket_create_listen(port), it does not listen on all interfaces as the docs indicate that it would. I was unable to connect to the machine using anything other than localhost (127.0.0.1). 

The workaround is to use socket_create, socket_bind (with 0.0.0.0 as the address) and socket_listen to accomplish the same task.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-08-07 21:21 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.


 [2005-08-15 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2006-08-03 13:27 UTC] jarcarlos at sapo dot pt
I have the same problem with PHP 5.1.4 version. The soket can't receive connections from internet, but can do it in local network. But when i put 0.0.0.0 in address socket_bind I begin to receive connections.

In some (many) connections i receive warning in socket_write and socket_read because "unable to write/read from socket [0]". 

My operating system is: Windows XP.
 [2007-03-13 06:36 UTC] mayank_10000 at yahoo dot com
i am using php 5.0.4 Ver. and i want to broad cast msg in local network using php so i am using this function 
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);

but if i am run this php file then generat error on page this

Fatal error: Call to undefined function socket_create() in C:\Program Files\Apache Group\Apache2\htdocs\mayank\socket\examp1.php on line 3

what i do for it pls reply me
 [2011-05-15 19:15 UTC] keithm at aoeex dot com
Same issue.  Small test script:

===================================================
<?php

$server = socket_create_listen(5900);
if (!$server){
	throw new Exception('Cannot create socket');
}

$client = socket_accept($server);
if (!$client){
	throw new Exception('Client connect failed.');
}

while ($client){
	$data = socket_read($client, 1024);
	if ($data != ""){
		$data = trim($data);

		socket_write($client, 'You said: '.$data."\r\n");
		if ($data=='bye'){
			socket_close($client);
			socket_close($server);
			$client=null;
		}
	}
	else {
		socket_close($client);
		socket_close($server);
		$client=null;
	}
}
===================================================

Environment
===================================================
Windows 7 64-bit

D:\php-trunk>php -v
PHP 5.3.99-dev (cli) (built: May 15 2011 09:31:01)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2011 Zend Technologies

(also fails in 5.3.6 release)


After running the script above:
===================================================
C:\Users\Keith>netstat -nap tcp

Active Connections

  Proto  Local Address          Foreign Address        State
  [..snip..]
  TCP    127.0.0.1:5900         0.0.0.0:0              LISTENING

C:\Users\Keith>nc -v 127.0.0.1 5900
sleek [127.0.0.1] 5900 (?) open
Testing
You said: Testing
123
You said: 123
bye
You said: bye

C:\Users\Keith>nc -v 192.168.0.6 5900
sleek [192.168.0.6] 5900 (?): connection refused
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 08 06:01:29 2024 UTC