<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.stream.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.stream-set-write-buffer.php',
    1 => 'stream_set_write_buffer',
    2 => 'Sets write file buffering on the given stream',
  ),
  'up' => 
  array (
    0 => 'ref.stream.php',
    1 => 'Stream Functions',
  ),
  'prev' => 
  array (
    0 => 'function.stream-set-timeout.php',
    1 => 'stream_set_timeout',
  ),
  'next' => 
  array (
    0 => 'function.stream-socket-accept.php',
    1 => 'stream_socket_accept',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/stream/functions/stream-set-write-buffer.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.stream-set-write-buffer" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">stream_set_write_buffer</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.3.0, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">stream_set_write_buffer</span> &mdash; <span class="dc-title">Sets write file buffering on the given stream</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.stream-set-write-buffer-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>stream_set_write_buffer</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> <code class="parameter">$stream</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$size</code></span>): <span class="type"><a href="language.types.integer.php" class="type int">int</a></span></div>

  <p class="para rdfs-comment">
   Sets the buffering for write operations on the given <code class="parameter">stream</code>
   to <code class="parameter">size</code> bytes.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.stream-set-write-buffer-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">stream</code></dt>
     <dd>
      <p class="para">
       The file pointer.
      </p>
     </dd>
    
    
     <dt><code class="parameter">size</code></dt>
     <dd>
      <p class="para">
       The number of bytes to buffer. If <code class="parameter">size</code>
       is 0 then write operations are unbuffered.  This ensures that all writes
       with <span class="function"><a href="function.fwrite.php" class="function">fwrite()</a></span> are completed before other processes are
       allowed to write to that output stream.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.stream-set-write-buffer-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns 0 on success, or another value if the request cannot be honored.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.stream-set-write-buffer-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 <span class="function"><strong>stream_set_write_buffer()</strong></span> example</strong></p>
    <div class="example-contents"><p>
     The following example demonstrates how to use
     <span class="function"><strong>stream_set_write_buffer()</strong></span> to create an unbuffered stream.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$fp </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #0000BB">$file</span><span style="color: #007700">, </span><span style="color: #DD0000">"w"</span><span style="color: #007700">);<br />if (</span><span style="color: #0000BB">$fp</span><span style="color: #007700">) {<br />  if (</span><span style="color: #0000BB">stream_set_write_buffer</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">) !== </span><span style="color: #0000BB">0</span><span style="color: #007700">) {<br />      </span><span style="color: #FF8000">// changing the buffering failed<br />  </span><span style="color: #007700">}<br />  </span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">, </span><span style="color: #0000BB">$output</span><span style="color: #007700">);<br />  </span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.stream-set-write-buffer-seealso">
  <h3 class="title">See Also</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.fopen.php" class="function" rel="rdfs-seeAlso">fopen()</a> - Opens file or URL</span></li>
   <li><span class="function"><a href="function.fwrite.php" class="function" rel="rdfs-seeAlso">fwrite()</a> - Binary-safe file write</span></li>
  </ul>
 </div>


</div><?php manual_footer($setup); ?>