소스 검색

document HTTP streaming

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@19223 44c647ce-9c0f-0410-b52a-842ac1e357ba
stas 16 년 전
부모
커밋
887024cc1a
1개의 변경된 파일60개의 추가작업 그리고 0개의 파일을 삭제
  1. 60 0
      documentation/manual/en/module_specs/Zend_Http_Client-Advanced.xml

+ 60 - 0
documentation/manual/en/module_specs/Zend_Http_Client-Advanced.xml

@@ -343,4 +343,64 @@ $_SESSION['cookiejar'] = $client->getCookieJar();
 ]]></programlisting>
         </example>
     </sect2>
+    <sect2 id="zend.http.client.streaming">
+        <title>Data Streaming</title>
+        <para>
+            By default, <classname>Zend_Http_Client</classname> accepts and returns data as PHP strings.
+            However, in many cases there are big files to be sent or received, thus keeping them
+            in memory might be unnecessary or too expensive. For these cases, <classname>Zend_Http_Client</classname>
+            supports reading data from files (and in general, PHP streams) and writing data to files (streams).  
+        </para>
+        <para>
+        	In order to use stream to pass data to <classname>Zend_Http_Client</classname>, 
+        	use <methodname>setRawData()</methodname> method with data argument being stream resource
+        	(e.g., result of <methodname>fopen()</methodname>).
+            <example id="zend.http.client.streaming.example-1">
+                <title>Sending file to HTTP server with streaming</title>
+                <programlisting language="php"><![CDATA[
+]]>
+$fp = fopen("mybigfile.zip", "r");
+$client->setRawData($fp, 'application/zip')->request('PUT');
+</programlisting>
+            </example>
+        </para>
+        <para>
+        Only PUT requests currently support sending streams to HTTP server.
+        </para>
+        
+        <para>
+        In order to receive data from the server as stream, use <methodname>setStream()</methodname>.
+        Optional argument specifies the filename where the data will be stored. If the argument is just 
+        TRUE (default), temporary file will be used and will be deleted once response object is destroyed.
+        Setting argument to FALSE disables the streaming functionality.  
+        </para>
+        
+        <para>
+        When using streaming, <methodname>request()</methodname> method will return object of class
+        <classname>Zend_Http_Client_Response_Stream</classname>, which has two useful methods:
+        <methodname>getStreamName()</methodname> will return the name of the file where the response is stored, 
+        and <methodname>getStream()</methodname> will return stream from which the response could be read.   
+        </para>
+        
+        <para>
+        You can either write the response to pre-defined file, or use temporary file for storing it and 
+        send it out or write it to another file using regular stream functions.  
+        <example id="zend.http.client.streaming.example-2">
+                <title>Receiving file from HTTP server with streaming</title>
+                <programlisting language="php"><![CDATA[
+]]>
+$client->setStreaming(); // will use temp file
+$response = $client->request('GET');
+// copy file
+copy($response->getStreamName(), "my/downloads/file");
+// use stream
+$fp = fopen("my/downloads/file2", "w");
+stream_copy_to_stream($response->getStream(), $fp);
+// Also can write to known file
+$client->setStreaming("my/downloads/myfile)->request('GET');
+</programlisting>
+            </example>
+        </para>
+        
+    </sect2>
 </sect1>