php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #27211 stream_socket_accept() returns Invalid argument
Submitted: 2004-02-10 14:28 UTC Modified: 2004-07-31 13:48 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: glox at glox dot be Assigned: nlopess (profile)
Status: Closed Package: Documentation problem
PHP Version: 5CVS-2004-02-12 OS: *
Private report: No CVE-ID: None
 [2004-02-10 14:28 UTC] glox at glox dot be
Description:
------------
stream_socket_accept() returns the following error with the example from the manual page:

Warning: stream_socket_accept(): accept failed: Invalid argument in /share/wolfd/serv.php on line 6

I'm running this on freeBSD 5.1 with the latest php snapshot at this moment.

Reproduce code:
---------------
Server:

<?php
$socket = stream_socket_server("udp://0.0.0.0:13", $errno, $errstr, STREAM_SERVER_BIND);
if (!$socket) {
   echo "ERROR: $errno - $errstr<br />\n";
} else {
  while ($conn = stream_socket_accept($socket)) {
   fwrite($conn, date("D M j H:i:s Y\r\n"));
   fclose($conn);
  }
  fclose($socket);
}
?>

Client:

<?php
$sock = stream_socket_client('udp://127.0.0.1:13');
fwrite($sock, "a\n"); //if I don't add this nothing happens
$get = fgets($sock);
echo $get;
fclose($sock);
?>

Expected result:
----------------
The connection to the client should open, it should send the time and close.

Actual result:
--------------
Warning: stream_socket_accept(): accept failed: Invalid argument in /share/wolfd/serv.php on line 6

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-02-11 15:43 UTC] sniper@php.net
I'm not sure if it's actually a bug..(just read the manual page for these funcs, never used them myself before :)

stream_socket_accept() also crashes, if you happen to use the 3rd parameter too..

 [2004-02-12 14:27 UTC] glox at glox dot be
Well the server script is copy pasted from the manual page.
So, or the example is wrong, or there is a bug with those functions.
 [2004-02-16 05:16 UTC] wez@php.net
*_accept() doesn't make sense for UDP (which is a connection*less* protocol).

I had a conversation about this example with Nuno
this weekend; he will fix the docs.  He also found
a segfault, but I don't have time to fix it right now.
 [2004-03-15 10:20 UTC] sniper@php.net
Assigning to Nuno. (Please report the possible crash in different report if you haven't done it already)

 [2004-03-15 10:27 UTC] nlopess@php.net
Shame on me, but I've lost the e-mails I've exchanged with Wez (my ISP fault).
I don't remeber very well how to reproduce the crash :(

Wez sent me some examples to fix the ones that are currently in the docs, but I've lost them... :-(
 [2004-04-30 13:53 UTC] i_kobayashi at rnk dot co dot jp
In communication by udp, it is not accept() but recvfrom(). However, since there is no means to acquire an address and a port from stream_socket_recvfrom(), a reply cannot be returned. Are there any of other means?
 [2004-06-02 22:28 UTC] flugelaar at pandora dot be
Is there news about this bug?
 [2004-06-03 19:53 UTC] nlopess@php.net
I had no time to fix this yet, but you should use something like:

$srv = stream_socket_server("udp://127.0.0.1:13");
do {
   $pkt = stream_socket_recvfrom($srv, 1, 0, $peer);
   stream_socket_sendto($srv, date("D M j H:i:s Y\r\n"), 0, $peer);
} while ($pkt !== false);
 [2004-07-31 13:48 UTC] nlopess@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 [2020-02-07 06:11 UTC] phpdocbot@php.net
Automatic comment on behalf of nlopess
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=90e6fc874c3ce8fd5b989282b219453961b5244c
Log: fix #27211: clarify how to use UDP server sockets #please review this
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 14:04:04 2025 UTC