<?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-context-set-default.php',
    1 => 'stream_context_set_default',
    2 => 'Set the default stream context',
  ),
  'up' => 
  array (
    0 => 'ref.stream.php',
    1 => 'Stream Functions',
  ),
  'prev' => 
  array (
    0 => 'function.stream-context-get-params.php',
    1 => 'stream_context_get_params',
  ),
  'next' => 
  array (
    0 => 'function.stream-context-set-option.php',
    1 => 'stream_context_set_option',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/stream/functions/stream-context-set-default.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.stream-context-set-default" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">stream_context_set_default</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">stream_context_set_default</span> &mdash; <span class="dc-title">Set the default stream context</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.stream-context-set-default-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>stream_context_set_default</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter">$options</code></span>): <span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span></div>

  <p class="simpara">
   Set the default stream context which will be used whenever file operations
   (<span class="function"><a href="function.fopen.php" class="function">fopen()</a></span>, <span class="function"><a href="function.file-get-contents.php" class="function">file_get_contents()</a></span>, etc...)
   are called without a context parameter. Uses the same syntax as
   <span class="function"><a href="function.stream-context-create.php" class="function">stream_context_create()</a></span>.
  </p>
 </div>

 
 <div class="refsect1 parameters" id="refsect1-function.stream-context-set-default-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">options</code></dt>
     <dd>
      <p class="para">
       The options to set for the default context.
      </p>
      <blockquote class="note"><p><strong class="note">Note</strong>: 
       <p class="para">
        <code class="parameter">options</code> must be an associative
        array of associative arrays in the format
        <code class="literal">$arr[&#039;wrapper&#039;][&#039;option&#039;] = $value</code>.
       </p>
      </p></blockquote>
     </dd>
    
   </dl>
  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-function.stream-context-set-default-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns the default stream context. 
  </p>
 </div>

 
 <div class="refsect1 examples" id="refsect1-function.stream-context-set-default-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="stream-context-set-default.example.basic">
    <p><strong>Example #1 <span class="function"><strong>stream_context_set_default()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$default_opts </span><span style="color: #007700">= [<br />  </span><span style="color: #DD0000">'http' </span><span style="color: #007700">=&gt; [<br />    </span><span style="color: #DD0000">'method' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">"GET"</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'header' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">"Accept-language: en\r\n" </span><span style="color: #007700">.<br />                </span><span style="color: #DD0000">"Cookie: foo=bar"</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'proxy'  </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">"tcp://10.54.1.39:8000"</span><span style="color: #007700">,<br />  ]<br />];<br /><br /></span><span style="color: #0000BB">$default </span><span style="color: #007700">= </span><span style="color: #0000BB">stream_context_set_default</span><span style="color: #007700">(</span><span style="color: #0000BB">$default_opts</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* Sends a regular GET request to proxy server at 10.54.1.39<br /> * For www.example.com using context options specified in $default_opts<br /> */<br /></span><span style="color: #0000BB">readfile</span><span style="color: #007700">(</span><span style="color: #DD0000">'http://www.example.com'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

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

 
 <div class="refsect1 seealso" id="refsect1-function.stream-context-set-default-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.stream-context-create.php" class="function" rel="rdfs-seeAlso">stream_context_create()</a> - Creates a stream context</span></li>
    <li><span class="function"><a href="function.stream-context-get-default.php" class="function" rel="rdfs-seeAlso">stream_context_get_default()</a> - Retrieve the default stream context</span></li>
    <li>Listing of supported wrappers with context options (<a href="wrappers.php" class="xref">Supported Protocols and Wrappers</a>).</li>
   </ul>
  </p>
 </div>


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