|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22474 fwrite hangs on invalid connection
Submitted: 2003-02-28 06:34 UTC Modified: 2003-03-16 01:00 UTC
Avg. Score:4.8 ± 0.4
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:0 (0.0%)
From: chuck at fuck dot org Assigned:
Status: No Feedback Package: Filesystem function related
PHP Version: 5CVS-2003-02-28 (dev) OS: FreeBSD 4.7
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: chuck at fuck dot org
New email:
PHP Version: OS:


 [2003-02-28 06:34 UTC] chuck at fuck dot org
When using a fsockopen resource that has been accepted, but is non-responsive, fwrite will use as much cpu as it can before the program is terminated by the time limit.

 if(false===($a=@fsockopen("tcp://$a", 1080, $err, $errstr, 10))) return false;
 $conn=pack('ccnN', '4', 1, 25, ip2long($ip)) .pack('a',$socksusers);
 stream_set_timeout($a, 15);

 if(!socks_write($a,$conn,9)) return false;

function socks_write(&$a,$b,$c=false) {
 if($c != $tmp) return false;
 return true;

This program will freeze at the fwrite command.
I've had this happen on PHP 4.3.0 and CVS

It only occurs when specific servers are addressed in the fsockopen. While I understand the server may be responding with garbage data, the fsockopen should not be returning the connection as success. Even with that case, I don't see reason for the fwrite to hang with high cpu usage.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-02-28 10:31 UTC]
Can you provide a bit more information?

I want to see a script like this:

$fp = fsockopen($host, $port, $err, $errstr, 10);
if (!$fp) {
   die("Connection failed: $err $errstr);
stream_set_timeout($fp, 15);
$n = fwrite($fp, "data");


But please fill in the $host and $port with addresses that I can use from my machine(s) so that I can try and replicate.

Alternatively, please read the docs here
and generate a backtrace from within the fwrite() when it is eating up the cpu:

Compile php with --enable-debug first then:

gdb ./sapi/cli/php
run myscript.php
[ wait for it to "hang" ]
[ press CTRL-C ]
bt full

Please post the backtrace at a URL and enter the link into this report.

If you can provide a reproducing script AND a backtrace, that is even more useful.

 [2003-03-16 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-2021 The PHP Group
All rights reserved.
Last updated: Thu May 06 22:02:20 2021 UTC