php.net |  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
Votes:4
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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
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) {
 $tmp=fwrite($a,$b,$c);
 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.


Patches

Pull Requests

History

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

I want to see a script like this:

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

fclose($fp);
?>

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 http://bugs.php.net/bugs-generating-backtrace.php
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-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 13:01:31 2024 UTC