|
|
@@ -168,56 +168,56 @@ $response = $client->request();
|
|
|
<para>
|
|
|
<code>fsockopen('tls://www.example.com', 443)</code>
|
|
|
</para>
|
|
|
-
|
|
|
+
|
|
|
<sect3 id="zend.http.client.adapters.socket.streamcontext">
|
|
|
<title>Customizing and accessing the Socket adapter stream context</title>
|
|
|
<para>
|
|
|
- Starting from Zend Framework 1.9, <classname>Zend_Http_Client_Adapter_Socket</classname>
|
|
|
+ Starting from Zend Framework 1.9, <classname>Zend_Http_Client_Adapter_Socket</classname>
|
|
|
provides direct access to the underlying <ulink url="http://php.net/manual/en/stream.contexts.php">stream context</ulink>
|
|
|
- used to connect to the remote server. This allows the user to pass
|
|
|
+ used to connect to the remote server. This allows the user to pass
|
|
|
specific options and parameters to the TCP stream, and to the SSL wrapper in
|
|
|
case of HTTPS connections.
|
|
|
</para>
|
|
|
-
|
|
|
+
|
|
|
<para>
|
|
|
You can access the stream context using the following methods of <classname>Zend_Http_Client_Adapter_Socket</classname>:
|
|
|
<itemizedlist>
|
|
|
<listitem>
|
|
|
<para>
|
|
|
<firstterm><classname>setStreamContext($context)</classname></firstterm>
|
|
|
- Sets the stream context to be used by the adapter. Can accept either
|
|
|
- a stream context resource created using the
|
|
|
- <ulink url="http://php.net/manual/en/function.stream-context-create.php"><classname>stream_context_create()</classname></ulink>
|
|
|
- PHP function, or an array of stream context options, in the same format provided to this function.
|
|
|
- Providing an array will create a new stream context using these options, and set it.
|
|
|
- </para>
|
|
|
- </listitem>
|
|
|
- <listitem>
|
|
|
- <para>
|
|
|
- <firstterm><classname>getStreamContext()</classname></firstterm>
|
|
|
- Get the stream context of the adapter. If no stream context was set,
|
|
|
- will create a default stream context and return it. You can then set
|
|
|
- or get the value of different context options using regular PHP stream
|
|
|
- context functions.
|
|
|
- </para>
|
|
|
- </listitem>
|
|
|
- </itemizedlist>
|
|
|
+ Sets the stream context to be used by the adapter. Can accept either
|
|
|
+ a stream context resource created using the
|
|
|
+ <ulink url="http://php.net/manual/en/function.stream-context-create.php"><classname>stream_context_create()</classname></ulink>
|
|
|
+ PHP function, or an array of stream context options, in the same format provided to this function.
|
|
|
+ Providing an array will create a new stream context using these options, and set it.
|
|
|
+ </para>
|
|
|
+ </listitem>
|
|
|
+ <listitem>
|
|
|
+ <para>
|
|
|
+ <firstterm><classname>getStreamContext()</classname></firstterm>
|
|
|
+ Get the stream context of the adapter. If no stream context was set,
|
|
|
+ will create a default stream context and return it. You can then set
|
|
|
+ or get the value of different context options using regular PHP stream
|
|
|
+ context functions.
|
|
|
+ </para>
|
|
|
+ </listitem>
|
|
|
+ </itemizedlist>
|
|
|
</para>
|
|
|
<example id="zend.http.client.adapters.socket.streamcontext.example-1">
|
|
|
<title>Setting stream context options for the Socket adapter</title>
|
|
|
<programlisting language="php"><![CDATA[
|
|
|
// Array of options
|
|
|
$options = array(
|
|
|
- 'socket' => array(
|
|
|
+ 'socket' => array(
|
|
|
// Bind local socket side to a specific interface
|
|
|
'bindto' => '10.1.2.3:50505'
|
|
|
),
|
|
|
'ssl' => array(
|
|
|
- // Verify server side certificate,
|
|
|
+ // Verify server side certificate,
|
|
|
// do not accept invalid or self-signed SSL certificates
|
|
|
'verify_peer' => true,
|
|
|
'allow_self_signed' => false,
|
|
|
-
|
|
|
+
|
|
|
// Capture the peer's certificate
|
|
|
'capture_peer_cert' => true
|
|
|
)
|
|
|
@@ -242,18 +242,21 @@ stream_context_set_option($context, $options);
|
|
|
// Now, preform the request
|
|
|
$response = $client->request();
|
|
|
|
|
|
-// If everything went well, you can now access the context again
|
|
|
+// If everything went well, you can now access the context again
|
|
|
$opts = stream_context_get_options($adapter->getStreamContext());
|
|
|
echo $opts['ssl']['peer_certificate'];
|
|
|
]]></programlisting>
|
|
|
</example>
|
|
|
- <note>
|
|
|
+
|
|
|
+ <note>
|
|
|
+ <para>
|
|
|
Note that you must set any stream context options before using the adapter
|
|
|
to preform actual requests. If no context is set before preforming HTTP requests
|
|
|
with the Socket adapter, a default stream context will be created. This context
|
|
|
- resource could be accessed after preforming any requests using the
|
|
|
- <classname>getStreamContext()</classname> method.
|
|
|
- </note>
|
|
|
+ resource could be accessed after preforming any requests using the
|
|
|
+ <classname>getStreamContext()</classname> method.
|
|
|
+ </para>
|
|
|
+ </note>
|
|
|
</sect3>
|
|
|
</sect2>
|
|
|
|
|
|
@@ -358,11 +361,13 @@ $client = new Zend_Http_Client('http://www.example.com', $config);
|
|
|
allows you to easily write your application in a way that allows a
|
|
|
proxy to be used optionally, according to a configuration parameter.
|
|
|
</para>
|
|
|
-
|
|
|
+
|
|
|
<note>
|
|
|
- Since the proxy adapter inherits from <classname>Zend_Http_Client_Adapter_Socket</classname>,
|
|
|
- you can use the stream context access method (see <xref linkend="zend.http.client.adapters.socket.streamcontext" />)
|
|
|
- to set stream context options on Proxy connections as demonstrated above.
|
|
|
+ <para>
|
|
|
+ Since the proxy adapter inherits from <classname>Zend_Http_Client_Adapter_Socket</classname>,
|
|
|
+ you can use the stream context access method (see <xref linkend="zend.http.client.adapters.socket.streamcontext" />)
|
|
|
+ to set stream context options on Proxy connections as demonstrated above.
|
|
|
+ </para>
|
|
|
</note>
|
|
|
</sect2>
|
|
|
|