<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.filesystem.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.touch.php',
    1 => 'touch',
    2 => 'Sets access and modification time of file',
  ),
  'up' => 
  array (
    0 => 'ref.filesystem.php',
    1 => 'Filesystem Functions',
  ),
  'prev' => 
  array (
    0 => 'function.tmpfile.php',
    1 => 'tmpfile',
  ),
  'next' => 
  array (
    0 => 'function.umask.php',
    1 => 'umask',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/filesystem/functions/touch.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.touch" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">touch</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">touch</span> &mdash; <span class="dc-title">Sets access and modification time of file</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.touch-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>touch</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$filename</code></span>, <span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.integer.php" class="type int">int</a></span></span> <code class="parameter">$mtime</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>, <span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.integer.php" class="type int">int</a></span></span> <code class="parameter">$atime</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   Attempts to set the access and modification times of the file named in the
   <code class="parameter">filename</code> parameter to the value given in
   <code class="parameter">mtime</code>. 
   Note that the access time is always modified, regardless of the number
   of parameters.
  </p>
  <p class="para">
   If the file does not exist, it will be created. 
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.touch-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">filename</code></dt>
     <dd>
      <p class="para">
       The name of the file being touched.
      </p>
     </dd>
    
    
     <dt><code class="parameter">mtime</code></dt>
     <dd>
      <p class="para">
       The touch time. If <code class="parameter">mtime</code> is <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>, 
       the current system <span class="function"><a href="function.time.php" class="function">time()</a></span> is used.
      </p>
     </dd>
    
    
     <dt><code class="parameter">atime</code></dt>
     <dd>
      <p class="para">
       If not <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>, the access time of the given filename is set to
       the value of <code class="parameter">atime</code>. Otherwise, it is set to
       the value passed to the <code class="parameter">mtime</code> parameter.
       If both are <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>, the current system time is used.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-function.touch-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> on success or <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> on failure.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.touch-changelog">
  <h3 class="title">Changelog</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Description</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       <code class="parameter">mtime</code> and <code class="parameter">atime</code>
       are now nullable.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.touch-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 <span class="function"><strong>touch()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">touch</span><span style="color: #007700">(</span><span style="color: #0000BB">$filename</span><span style="color: #007700">)) {<br />    echo </span><span style="color: #0000BB">$filename </span><span style="color: #007700">. </span><span style="color: #DD0000">' modification time has been changed to present time'</span><span style="color: #007700">;<br />} else {<br />    echo </span><span style="color: #DD0000">'Sorry, could not change modification time of ' </span><span style="color: #007700">. </span><span style="color: #0000BB">$filename</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-2">
    <p><strong>Example #2 <span class="function"><strong>touch()</strong></span> using the <code class="parameter">mtime</code> parameter</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">// This is the touch time, we'll set it to one hour in the past.<br /></span><span style="color: #0000BB">$time </span><span style="color: #007700">= </span><span style="color: #0000BB">time</span><span style="color: #007700">() - </span><span style="color: #0000BB">3600</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Touch the file<br /></span><span style="color: #007700">if (!</span><span style="color: #0000BB">touch</span><span style="color: #007700">(</span><span style="color: #DD0000">'some_file.txt'</span><span style="color: #007700">, </span><span style="color: #0000BB">$time</span><span style="color: #007700">)) {<br />    echo </span><span style="color: #DD0000">'Whoops, something went wrong...'</span><span style="color: #007700">;<br />} else {<br />    echo </span><span style="color: #DD0000">'Touched file with success'</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

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


 <div class="refsect1 notes" id="refsect1-function.touch-notes">
  <h3 class="title">Notes</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para">Note that time resolution may differ
from one file system to another.</p></p></blockquote>
 </div>

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