note 76468 added to function.fsockopen

From: Date: Tue, 17 Jul 2007 11:37:59 +0000
Subject: note 76468 added to function.fsockopen
Groups: php.notes 
Request: Send a blank email to php-notes+get-128646@lists.php.net to get a copy of this message
I ran into a problem where I needed to make an fsockopen() style connection from one specific ip address on a server with multiple ip aliases. Unfortunately fsockopen() does not allow the specification of a source address making it unsuitable. I could not find any other solutions elsewhere so here is mine for those with php 5.1.0 or greater. // connect to the internet using the '192.168.0.100' IP $opts = array('socket' => array('bindto' => '192.168.0.100:0')); $context = stream_context_create($opts); $fp = stream_socket_client("tcp://www.example.com:80", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context); Now $fp can be used like a resource handle returned by a vanilla fsockopen() call! ---- Server IP: 203.89.181.184 Probable Submitter: 202.74.222.43 ---- Manual Page -- http://www.php.net/manual/en/function.fsockopen.php Edit -- https://master.php.net/note/edit/76468 Del: integrated -- https://master.php.net/note/delete/76468/integrated Del: useless -- https://master.php.net/note/delete/76468/useless Del: bad code -- https://master.php.net/note/delete/76468/bad+code Del: spam -- https://master.php.net/note/delete/76468/spam Del: non-english -- https://master.php.net/note/delete/76468/non-english Del: in docs -- https://master.php.net/note/delete/76468/in+docs Del: other reasons-- https://master.php.net/note/delete/76468 Reject -- https://master.php.net/note/reject/76468 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#128646) next »