socket problem

This is a discussion on socket problem within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi, I use fsockopen to open a connection on a POP3 server. I use fwrite to send command to the ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-02-2005
WebRod
 
Posts: n/a
Default socket problem

Hi,

I use fsockopen to open a connection on a POP3 server.

I use fwrite to send command to the pop3 server.

I have a problem when the call between 2 fwrite is too long.
The connection is closed.
If thought the 2nd fwrite will return false (because the connection is
closed), but it does a strange thing.
Php displays errors messages again and again and again...
Theses error messages are all the same and explain that the connection has
been cancelled by host.
The only solution to stop the error messages is to kill the apache task!

Do you know this bug??
It really should return false and not try again and again to write!!

Can i know if the connection has been cancelled before i call the fwrite
function so i don't have this problem anymore?

Thanks you for your help

Rod


Reply With Quote
  #2 (permalink)  
Old 02-03-2005
Senator Jay Billington Bulworth
 
Posts: n/a
Default Re: socket problem

"WebRod" <nomail@bouygtel.fr> wrote in
news:42011060$0$26205$7a628cd7@news.club-internet.fr:

> Hi,
>
> I use fsockopen to open a connection on a POP3 server.
>
> I use fwrite to send command to the pop3 server.
>
> I have a problem when the call between 2 fwrite is too long.
> The connection is closed.
> If thought the 2nd fwrite will return false (because the connection is
> closed), but it does a strange thing.
> Php displays errors messages again and again and again...
> Theses error messages are all the same and explain that the connection
> has been cancelled by host.
> The only solution to stop the error messages is to kill the apache task!
>
> Do you know this bug??
> It really should return false and not try again and again to write!!
>
> Can i know if the connection has been cancelled before i call the fwrite
> function so i don't have this problem anymore?
>
> Thanks you for your help
>
> Rod


Which version of PHP are you using? I tested some code against Apache with
low settings for Timeout and KeepAliveTimeout, but I can't reproduce this
locally even with error_reporting set to E_ALL. Here is the code I used:

<?php
ini_set('error_reporting', E_ALL);
$sock = fsockopen('localhost', 80);
while(1){
$bytes = fwrite($sock, 'test');
if(!$bytes) die("fwrite() failed\n");
echo "sent $bytes bytes\n";
sleep(5);
}
?>

The output was:

= = = = = = = = = =
$ php test.php
sent 4 bytes
sent 4 bytes

Notice: fwrite(): send of 4 bytes failed with errno=32 Broken pipe in
/usr/home/foo/test.php on line 5 fwrite() failed
= = = = = = = = = =

I'm not able to reproduce the repeated error issue, and fwrite() does fail
for me as expected. I'm running PHP 4.3.10.

hth

--

Bulworth : PHP/MySQL/Unix | Email : str_rot13('f@fung.arg');
--------------------------|---------------------------------
<http://www.phplabs.com/> | PHP scripts, webmaster resources
Reply With Quote
  #3 (permalink)  
Old 02-03-2005
WebRod
 
Posts: n/a
Default Re: socket problem

Hi,

thanks you for your help!
> Which version of PHP are you using?

Php version 4.3.3 (with easyphp and windows)

I have run this code:
ini_set('error_reporting', E_ALL);
$sock = fsockopen('localhost', 80);
$i=0;
while($i<5){
$i++;
$bytes = fwrite($sock, 'test');
if(!$bytes) die("fwrite() failed\n");
echo "sent $bytes bytes\n";
sleep(30);
}
die();

OUTPUT is:
sent 4 bytes sent bytes
Notice: fwrite(): send of 4 bytes failed with errno=0 Une connexion établie
a été abandonnée par un logiciel de votre ordinateur hôte. in c:\program
files\easyphp1-7\www\localebay\test.php on line 7
Notice: fwrite(): send of 5 bytes failed with errno=0 Une connexion établie
a été abandonnée par un logiciel de votre ordinateur hôte. in c:\program
files\easyphp1-7\www\localebay\test.php on line 7
Notice: fwrite(): send of 6 bytes failed with errno=0 Une connexion établie
a été abandonnée par un logiciel de votre ordinateur hôte. in c:\program
files\easyphp1-7\www\localebay\test.php on line 7
Notice: fwrite(): send of 7 bytes failed with errno=0 Une connexion établie
a été abandonnée par un logiciel de votre ordinateur hôte. in c:\program
files\easyphp1-7\www\localebay\test.php on line 7
Notice: fwrite(): send of 8 bytes failed with errno=0 Une connexion établie
a été abandonnée par un logiciel de votre ordinateur hôte. in c:\program
files\easyphp1-7\www\localebay\test.php on line 7
Notice: fwrite(): send of 9 bytes failed with errno=0 Une connexion établie
a été abandonnée par un logiciel de votre ordinateur hôte. in c:\program
files\easyphp1-7\www\localebay\test.php on line 7
Notice: fwrite(): send of 10 bytes failed with errno=0 Une connexion établie
a été abandonnée par un logiciel de votre ordinateur hôte. in c:\program
files\easyphp1-7\www\localebay\test.php on line 7
....
etc etc etc

And i need to kill the apache task!!

Do you see the number of bytes???
4 then 5 then 6....then 8196 then 8197 etc etc!!! (how is it possible?)

> I'm not able to reproduce the repeated error issue, and fwrite() does fail
> for me as expected. I'm running PHP 4.3.10.


You are lucky ;)

Any idea?

Rod


Reply With Quote
  #4 (permalink)  
Old 02-03-2005
Senator Jay Billington Bulworth
 
Posts: n/a
Default Re: socket problem

"WebRod" <nomail@bouygtel.fr> wrote in
news:42020556$0$26208$7a628cd7@news.club-internet.fr:

> Hi,
>
> thanks you for your help!
>> Which version of PHP are you using?

> Php version 4.3.3 (with easyphp and windows)
>
> I have run this code:
> ini_set('error_reporting', E_ALL);
> $sock = fsockopen('localhost', 80);
> $i=0;
> while($i<5){
> $i++;
> $bytes = fwrite($sock, 'test');
> if(!$bytes) die("fwrite() failed\n");
> echo "sent $bytes bytes\n";
> sleep(30);
> }
> die();
>
> OUTPUT is:
> sent 4 bytes sent bytes
> Notice: fwrite(): send of 4 bytes failed with errno=0 Une connexion
> établie a été abandonnée par un logiciel de votre ordinateur hôte. in
> c:\program files\easyphp1-7\www\localebay\test.php on line 7
> Notice: fwrite(): send of 5 bytes failed with errno=0 Une connexion
> établie a été abandonnée par un logiciel de votre ordinateur hôte. in
> c:\program files\easyphp1-7\www\localebay\test.php on line 7
> Notice: fwrite(): send of 6 bytes failed with errno=0 Une connexion
> établie a été abandonnée par un logiciel de votre ordinateur hôte. in
> c:\program files\easyphp1-7\www\localebay\test.php on line 7
> Notice: fwrite(): send of 7 bytes failed with errno=0 Une connexion
> établie a été abandonnée par un logiciel de votre ordinateur hôte. in
> c:\program files\easyphp1-7\www\localebay\test.php on line 7
> Notice: fwrite(): send of 8 bytes failed with errno=0 Une connexion
> établie a été abandonnée par un logiciel de votre ordinateur hôte. in
> c:\program files\easyphp1-7\www\localebay\test.php on line 7
> Notice: fwrite(): send of 9 bytes failed with errno=0 Une connexion
> établie a été abandonnée par un logiciel de votre ordinateur hôte. in
> c:\program files\easyphp1-7\www\localebay\test.php on line 7
> Notice: fwrite(): send of 10 bytes failed with errno=0 Une connexion
> établie a été abandonnée par un logiciel de votre ordinateur hôte. in
> c:\program files\easyphp1-7\www\localebay\test.php on line 7
> ...
> etc etc etc
>
> And i need to kill the apache task!!
>
> Do you see the number of bytes???
> 4 then 5 then 6....then 8196 then 8197 etc etc!!! (how is it possible?)


Hi Rod,

I am a Unix guy, I haven't tried PHP on Windows, and I'm not familiar with
EasyPHP. All I can suggest at this point is to upgrade to the latest PHP
(4.3.10) ... I'm not sure how or if that would work with EasyPHP.

One thing I do see is that PHP is issuing "Notice" messages, which are not
necessarily errors. If you set your php.ini for:

error_reporting = E_ALL & ~E_NOTICE

Those messages won't appear. But that won't help the root problem.

I'm hoping that someone who is more familiar with PHP on Windows can help
out.

hth


--
Bulworth : PHP/MySQL/Unix | Email : str_rot13('f@fung.arg');
--------------------------|---------------------------------
<http://www.phplabs.com/> | PHP scripts, webmaster resources
Reply With Quote
  #5 (permalink)  
Old 02-03-2005
WebRod
 
Posts: n/a
Default Re: socket problem

> I'm hoping that someone who is more familiar with PHP on Windows can help

You're right, It was a php version problem!!
I installed 4.3.10 and it works fine (i have only one error message when the
connection has been cancelled!!).

Thanks you.

Rod


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 11:01 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0