|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #50047 interface binding for fsockopen (like socket_bind)
Submitted: 2009-11-01 00:26 UTC Modified: 2011-12-22 11:37 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: naox at o2 dot pl Assigned:
Status: Wont fix Package: Network related
PHP Version: 5.2.11 OS: -
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2009-11-01 00:26 UTC] naox at o2 dot pl
PHP really needs interface binding for fsockopen() (like socket_bind())


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-03 03:06 UTC]
is this some thing what you are looking for ?
$fp = fsockopen("tcp://", 8080);

$fp = fsockopen("unix:///tmp/mysocket", ..);

 [2009-11-03 04:40 UTC] naox at o2 dot pl
nope. this would be setting destination not source interface. Check out
this however is for socket functions not "network" like fsockopen
 [2010-12-20 13:18 UTC]
-Package: Feature/Change Request +Package: Network related
 [2011-12-21 17:32 UTC] drclue at drclue dot net
I know this is an OLD thread to be bumping , but the missing bind facility in 
fsockopen() is exactly my problem today.

The knee jerk thought that most people have is that one is trying to
bind as a server, BUT in this use case I'm binding the client.

The particular application is an ip hygiene tester for a level 3 networking
company that verifies if particular source IP addresses can send mail, prior 
to leasing them out to corporate clients like Walmart. We do various DNS lookups
to spamhaus servers , and as a final test send test mails to test email accounts
we have established at the target servers of interest to the clients to verify
the /24 ip ranges will indeed deliver mail. (THIS IS NOT A SPAM SYSTEM).  

The server I'm developing on is configured with multiple ip addresses and the 
application needs to bind the client socket to perform the tests.

My existing mail routines use fsocket functions , so I'm having to investigate
various work arounds such as making a stream wrapper just to get that bind 
function in there. I really don't want to recreate all the feof , fread , fgets 
etc. logic.
 [2011-12-22 11:37 UTC]
-Status: Open +Status: Wont fix
 [2011-12-22 11:37 UTC]
stream_socket_client already exists for this purpose:

function test($a) {
        $s = stream_socket_client(
                $errno, $errstr, 1,
                        'socket' => array('bindto' => "[$a]:1224")
        fwrite($s, "GET /whoami HTTP/1.0\r\n\r\n");
        while ($f = fgets($s)) { $line = $f; }
        echo $line, "\n";

One could also more simply have used file_get_contents with the http wrapper in this situation.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jul 18 21:01:27 2024 UTC