#28136 [Com]: Problems with connection of a non blocking socket

2007-01-19 Thread fakeman at i dot ua
 ID:   28136
 Comment by:   fakeman at i dot ua
 Reported By:  daniele-dll at yahoo dot it
 Status:   No Feedback
 Bug Type: Sockets related
 Operating System: Windows\Linux
 PHP Version:  5.0.0RC1
 New Comment:

You wrote incorrect code a little. You must not check return value of
socket_get_option after socket_connect immediately because some
operations (like socket creation) take a long time to execute, mostly
because they involve talking to another host, which may have an
exruciating long timeout on it.
You should use socket_select and when select (or related interface)
says that the socket is ready for writing, you can call
socket_get_option($SOCKET, SOL_SOCKET, SO_ERROR, ...) on it. And now
socket_get_option will return with the error socket_connect would have
indicated, had it been called in a blocking manner. If the error is 0,
the connect succeeded.
As you remember socket_select have timeout paramer and this parameter
give some time to connect or no socket.


Previous Comments:


[2005-02-03 01:00:06] 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".



[2005-01-26 04:49:06] [EMAIL PROTECTED]

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 ,
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/




[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




#28136 [Com]: Problems with connection of a non blocking socket

2004-07-09 Thread snodge at custard dot org
 ID:   28136
 Comment by:   snodge at custard dot org
 Reported By:  daniele-dll at yahoo dot it
 Status:   Open
 Bug Type: Sockets related
 Operating System: Windows\Linux
 PHP Version:  5.0.0RC1
 New Comment:

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";


Previous Comments:


[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