#28136 [Opn->Fbk]: Problems with connection of a non blocking socket
| From: | sniper@php.net | Date: | Wed, 26 Jan 2005 03:49:08 +0000 |
| Subject: | #28136 [Opn->Fbk]: Problems with connection of a non blocking socket | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-72836@lists.php.net to get a copy of this message | ||
ID: 28136
Updated by: sniper@php.net
Reported By: daniele-dll at yahoo dot it
-Status: Open
+Status: Feedback
Bug Type: Sockets related
Operating System: Windows\Linux
PHP Version: 5.0.0RC1
New Comment:
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.
Also try the latest CVS snapshot from http://snaps.php.net/
Previous Comments:
------------------------------------------------------------------------
[2004-07-10 00:43:48] snodge at custard dot org
Hi - I have the same issue, althought I am using PHP 5.0RC3 (cli) from
Linux. Here is some of the code that I am using - I added an echo
statement so that I could see what was happening when I connected with
more than one client at a time:
$port = 5000;
if (!$sock = socket_create_listen($port)) {
echo socket_strerror(socket_last_error());
}
if (!socket_set_option($sock, SOL_SOCKET, SO_REUSEADDR, 1)) {
echo socket_strerror(socket_last_error());
}
if (!socket_set_nonblock($sock)) {
echo socket_strerror(socket_last_error());
}
while (true)
{
$msgsock == FALSE;
do
{
@$msgsock = socket_accept($sock);
} while ($msgsock == FALSE);
echo "Received connection from $msgsock\n";
------------------------------------------------------------------------
[2004-04-24 16:56:04] daniele-dll at yahoo dot it
Description:
------------
Hi to all
i'm tring to write a little application with PHP using Socket, the
external module, not fsockopen function or similar.
I've noticed that, with this, and previous version of php, that after i
create a socket and set it as non blocking socket, when i try to connect
using
socket_get_option($SOCKET, SOL_SOCKET, SO_ERROR)
i recive EVER 0
Instead i should recive 115
If socket_get_option, with these params, return 0, it mean that
connection is done and i can send datas, but if i send datas i get a
warning that say that socket is in a connection state so i can't send
datas.
There is some parts of code:
$this->socket[$sock_id]['resource'] = socket_create(AF_INET,
SOCK_STREAM, SOL_TCP);
if (!is_resource($this->socket[$sock_id]['resource']))
die("Unable to create socket! " .
socket_strerror(socket_last_error()) . "\r\n");
if (!socket_set_option($this->socket[$sock_id]['resource'], SOL_SOCKET,
SO_REUSEADDR, 1)) {
die("Unable to set to as REUSABLE socket! " .
socket_strerror(socket_last_error($this->socket[$sock_id]['resource']))
. "\r\n");
after i set socket as reusable (but php gimme me the same problem
without this line too) and, after, if i need, i bind socket to a
specific IP and PORT
after there is this code:
@socket_connect($this->socket[$sock_id]['resource'],
$this->socket[$sock_id]['remote_host'],
$this->socket[$sock_id]['remote_port']);
while (($ris = @socket_get_option($this->socket[$sock_id]['resource'],
SOL_SOCKET, SO_ERROR)) == 115) {
echo "--> " . $ris . "\r\n";
}
echo "\r\n--> " . $ris . "\r\n";
If you run this code it will exit immedatly printing:
--> 0
Infact, after, if you try to write to socket, you will get a warning
I haven't modified php.ini, and i've tried to run this code, using only
socket extension, on windows and on linux
I use apache 1.3.29 on windows and on linux
bye
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=28136&edit=1