php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #21656 fclose() don't close the socket
Submitted: 2003-01-15 07:31 UTC Modified: 2003-01-31 01:00 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: azevedo at tchelinux dot com dot br Assigned:
Status: No Feedback Package: Sockets related
PHP Version: 4.3.0 OS: Linux (Slackware)
Private report: No CVE-ID: None
 [2003-01-15 07:31 UTC] azevedo at tchelinux dot com dot br
Hi,

I've made a script to connect using fsockopen() (not pfsockopen()), and check the timeout into while. If the connection got a time out, I close the socket and restart the request again.
The problem is that when I got some network problem that made the connection to be lost, the PHP script simple doesn't close this socket with fclose() and when I open the socket again, I can't send or receive any data.
The script is running at shell, and is fetching many web pages to insert into a mysql database.
All works fine, till I got any network problem.

I've searched all the documentation and bug reports and there's nothing talking about the fclose() to not real close the socket.

There's any other way to really force the socket to be closed and oppened again in the same script?

Thanks in advice.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-01-15 08:02 UTC] wez@php.net
Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at
http://bugs.php.net/how-to-report.php

If you can provide more information, feel free to add it
to this bug and change the status back to "Open".

Thank you for your interest in PHP.



 [2003-01-15 17:45 UTC] php at interfaces dot fr
I am running PHP 4.3, RedHat Linux 7.3, Apache-1.3.27-2 and have still the problem :

1-$fp = fsockopen ($tiphost[$i],25,&$errno,&$errstr,&$TimeOut);
2-$tstatus = stream_get_meta_data ($fp);
3-if ($tstatus["eof"]) {
4-   $output = '114 Connection unexpectedly closed';
5-}
6-$err = fclose ($fp);

At line 6 it goes (sometimes) wrong, I guess for the same reason as described here and I get Apache PIDs running for days now...
I tried set_time_limit () but as fclose() is "out" of PHP (I think) it does not make the job :-(

/server-status gives for example :
M CPU   SS    Req 
K 34.48 74295 280513
which means the server child is in Keepalive mode, used 34.48 secs of CPU (stalled), not working for 74295 secs (growing), and have been working for 280513 secs (stalled)
 [2003-01-15 17:56 UTC] wez@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-STABLE-latest.zip

There was a problem with the errstr parameter to fsockopen that has been fixed in the STABLE snapshots.

Please try one of those and report back here.

Also, please read the docs for stream_get_meta_data()
and make sure that you understand the difference between
the eof property listed there and the return value of the
feof() function.

 [2003-01-15 20:55 UTC] php at interfaces dot fr
Thanks, it goes better... but it is still not perfect.
I can (nearly) reproduce the behavior with port 25 of any of [205.158.62.23], [205.158.62.25], [205.158.62.27], [205.158.62.41] while waiting fo smtp greetings

after $fp = fsockopen returns a valid $fp
$buffer = fgets ($fp); 
$tstatus = stream_get_meta_data ($fp);
$tstatus["eof"] evaluates to TRUE

I then try to fclose($fp) but the script hangs there (cf. supra)
 [2003-01-15 21:24 UTC] wez@php.net
Please read this:
http://bugs.php.net/bugs-generating-backtrace.php
and then run your httpd under gdb as described in the section "if you can't get a core file".

** make sure your PHP is compiled with --enable-debug **

When you get the script to hang, press CTRL-C to interrupt and then type "bt full".

copy-and-paste the backtrace into a text file, and make a tar ball from it, along with the script that you were running to cause the problem, and put it online somewhere that I can download it.

Thanks!


 [2003-01-31 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over 2 weeks, 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".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Dec 04 12:01:30 2024 UTC