php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36036 fsockopen will not connect with bindto option
Submitted: 2006-01-16 21:41 UTC Modified: 2006-01-16 22:45 UTC
From: jason at eblasterpro dot com Assigned:
Status: Not a bug Package: Sockets related
PHP Version: 5.1.2 OS: Mandrake 10.2
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jason at eblasterpro dot com
New email:
PHP Version: OS:

 

 [2006-01-16 21:41 UTC] jason at eblasterpro dot com
Description:
------------
I passed this option
$options = array('socket' => array('bindto' => '10.1.14.1:9000'));
into 
$context = stream_context_create($options);
$fp = @$openfunc($this->addr, $this->port, $errno, $errstr, $timeout, $context);
Which caused my program to stop connecting all together.
The ip and port are valid.

Expected result:
----------------
Pear Socket.php has a place for options to be passed in, so I thought it would bind

Actual result:
--------------
Could never connect to remote machine

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-01-16 21:46 UTC] tony2001@php.net
Remove the @ from the function call and post the error you get (if any).
And make sure your 10.1.14.1 is *your* IP and port #9000 is not blocked by a firewall (or better just turn off any firewalls/filters).
 [2006-01-16 22:35 UTC] jason at eblasterpro dot com
<b>Warning</b>:  fsockopen() expects at most 5 parameters, 6 given in <b>/home/home/virtualhosts/trendex/lib/Net/Socket4.php</b> on line <b>133</b><br />

Pear's Socket.php contain the following in its connect function.   The must have wrote this assuming fsockopen would accept options one day.

$openfunc = $this->persistent ? 'pfsockopen' : 'fsockopen';
$errno = 0;
$errstr = '';
if ($options && function_exists('stream_context_create')) {
if ($this->timeout) {
$timeout = $this->timeout;
} else {
$timeout = 0;
}
$context = stream_context_create($options);
$fp = $openfunc($this->addr, $this->port, $errno, $errstr, $timeout, $context);
} else {
if ($this->timeout) {
$fp = $openfunc($this->addr, $this->port, $errno, $errstr, $this->timeout);
} else {
$fp = $openfunc($this->addr, $this->port, $errno, $errstr);
}
}
 [2006-01-16 22:45 UTC] tony2001@php.net
The error message is quite descriptive - (p)fsockopen() doesn't even have such parameter.
See http://php.net/fsockopen
No bug here.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 19:01:37 2025 UTC