php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23149 fsockopen uses port as hostname
Submitted: 2003-04-10 08:50 UTC Modified: 2003-04-28 11:16 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: fcv at dev6 dot com Assigned:
Status: No Feedback Package: Sockets related
PHP Version: 4.3.1 OS: Windows XP Pro
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: fcv at dev6 dot com
New email:
PHP Version: OS:

 

 [2003-04-10 08:50 UTC] fcv at dev6 dot com
Using fsockopen with the only 2 required parameters (hostname and port) like this fails:

 $myfilepointer = fsockopen($this->host, $this->port);

And returns the following error:

Warning: fsockopen() [function.fsockopen]: unable to connect to :23 in c:\programas\apache group\apache\htdocs\es-operadores\engine\telnet.php on line 97

The hostname is "10.1.2.9" (ip of my telnet server)
The port is 23.

$this is my telnet class initialized properly before use like this

$telnet = new telnet($hostname, $port);

function telnet($hostname, $port){
    $this->host = $hostname;
    $this->port = $port;
    ...
}

and line 97 is
 $this->sock = fsockopen($this->$host, $this->port);

This setup worked perfectly with PHP 4.2.x and stopped working when i upgraded to 4.3.1.

Now, the script attempts to connect to host "23" which is obviously wrong. It assumes the second argument of fsockopen to be the host instead of port.

If i insert a protocol argument before my host, it dumps data at an amazingly brutal rate to Internet Explorer causing it to hog my system memory and CPU (actualy, causes a memory leak in explorer. if i don't ctrl-alt-del and kill explorer, it uses up to 1GB of ram).

Am i using the function properly? According to the online documentation, yes! One weird thing is that you mention the protocol argument is only mandatory if i use UDP and it is specified and a prefix of the hostname (protocol://hopstname) and not as a separate argument. But Dreamweaver MX autocomplete shows fsockopen(udp://, hostname, port, err1, err2, timeout).

Thanks in advance!

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-04-10 08:54 UTC] fcv at dev6 dot com
that syntax error on line 97 is not in my code. i didnt copy paste it.

the original line 97 is
$this->sock = fsockopen($this->host, $this->port);

//the syntax error was ($this->$host)
 [2003-04-10 09:01 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

On the line before the fsockopen call, add this line:
debug_zval_dump($this->host);

If it displays the correct host name, please try a snapshot.  If it does not display the correct host name, the bug is elsewhere in your script.

 [2003-04-21 09:22 UTC] sniper@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 [2003-04-21 10:32 UTC] fcv at dev6 dot com
Tried using debug_zval_dump($this->host); today (21) and it displays the correct hostname:

"string(8) "10.1.2.9" refcount(2)"

Downloading snapshot now. Will post results later on today.
 [2003-04-21 10:41 UTC] fcv at dev6 dot com
Additionally, the error code and errormsg are clear UNTIL i try my first read on the stream.
I've seen comments on this situation somewhere on this site, and their solution (specify a timeout value) does not work at all.

Behaviour is exactly the same on the latest snapshot (downloaded a few minutes earlier)
 [2003-04-21 14:50 UTC] pollita@php.net
First, to clear that point up, DreamweaverMX is wrong.  Protocol is specified in hostname or not at all.

Second, Try using "tcp://10.1.2.9" for your hostname and see if it helps.

Lastly, I'd like to ask that you post your entire source code somewhere so that the problem can be investigated more thoroughly.
 [2003-04-28 11:16 UTC] sniper@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC