0

ZEND_HTTP_CLIENTを使用しています:

$config = array(
  'adapter'      => 'Zend_Http_Client_Adapter_Socket',
  'ssltransport' => 'tls',
  'timeout'      =>  30
);
$client  = new Zend_Http_Client($url , $config);

このリクエストを行うときにIPを変更する方法はありますか?現在、サーバー上で約4つのIPを使用できますか?

4

1 に答える 1

2

これは、使用しているアダプターを介して変更できます。ソケットアダプタを使用している場合:

$options = array(
    'socket' => array(
        // Bind local socket side to a specific interface
        'bindto' => '10.1.2.3:50505'
    )
);

// Create an adapter object and attach it to the HTTP client
$adapter = new Zend_Http_Client_Adapter_Socket();
$client = new Zend_Http_Client();
$client->setAdapter($adapter);

// Method 1: pass the options array to setStreamContext()
$adapter->setStreamContext($options);

// Method 2: create a stream context and pass it to setStreamContext()
$context = stream_context_create($options);
$adapter->setStreamContext($context);

// Method 3: get the default stream context and set the options on it
$context = $adapter->getStreamContext();
stream_context_set_option($context, $options);

// Now, preform the request
$response = $client->request();

上記は実際にはZendマニュアルからコピー/貼り付けされています。

ZendのCurlAdapterを使用している場合は、CURLOPT_INTERFACECurl 設定を渡すことができます。

$adapter = new Zend_Http_Client_Adapter_Curl();
$client = new Zend_Http_Client();
$client->setAdapter($adapter);
$adapter->setConfig(array(
    'curloptions' => array(
        CURLOPT_INTERFACE => '192.168.1.2'
    )
));
于 2013-02-08T11:49:46.003 に答える