<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Opens a file</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.eio-nthreads.html">eio_nthreads</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.eio-poll.html">eio_poll</a></div> <div class="up"><a href="ref.eio.html">Eio Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.eio-open" class="refentry"> <div class="refnamediv"> <h1 class="refname">eio_open</h1> <p class="verinfo">(PECL eio >= 0.0.1dev)</p><p class="refpurpose"><span class="refname">eio_open</span> — <span class="dc-title">Opens a file</span></p> </div> <div class="refsect1 description" id="refsect1-function.eio-open-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">resource</span> <span class="methodname"><strong>eio_open</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$path</code></span> , <span class="methodparam"><span class="type">int</span> <code class="parameter">$flags</code></span> , <span class="methodparam"><span class="type">int</span> <code class="parameter">$mode</code></span> , <span class="methodparam"><span class="type">int</span> <code class="parameter">$pri</code></span> , <span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$callback</code></span> [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$data</code><span class="initializer"> = NULL</span></span> ] )</div> <p class="para rdfs-comment"> <span class="function"><strong>eio_open()</strong></span> opens file specified by <em><code class="parameter">path</code></em> in access mode <em><code class="parameter">mode</code></em> with </p> </div> <div class="refsect1 parameters" id="refsect1-function.eio-open-parameters"> <h3 class="title">Parameters</h3> <dl> <dt> <span class="term"><em><code class="parameter">path</code></em></span> <dd> <p class="para"> Path of the file to be opened. <div class="warning"><strong class="warning">Warning</strong><p class="simpara"> In some SAPIs(e.g. <em class="emphasis">PHP-FPM</em>) it could fail, if you don't specify full path. </p></div> </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">flags</code></em></span> <dd> <p class="para">One of <em class="emphasis">EIO_O_*</em> constants, or their combinations. <em class="emphasis">EIO_O_*</em> constants have the same meaning, as their corresponding <em class="emphasis">O_*</em> counterparts defined in <em>fnctl.h</em> C header file. Default is <strong><code>EIO_O_RDWR</code></strong>. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">mode</code></em></span> <dd> <p class="para">One of <em class="emphasis">EIO_S_I*</em> constants, or their combination (via bitwise OR operator). The constants have the same meaning as their <em class="emphasis">S_I*</em> counterparts defined in <a href="http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_stat.h.html" class="link external">» sys/stat.h</a> C header file. Required, if a file is created. Otherwise ignored. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">pri</code></em></span> <dd> <p class="para">The request priority: <strong><code>EIO_PRI_DEFAULT</code></strong>, <strong><code>EIO_PRI_MIN</code></strong>, <strong><code>EIO_PRI_MAX</code></strong>, or <strong><code>NULL</code></strong>. If <strong><code>NULL</code></strong> passed, <em><code class="parameter">pri</code></em> internally is set to <strong><code>EIO_PRI_DEFAULT</code></strong>. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">callback</code></em></span> <dd> <p class="para"> <em><code class="parameter">callback</code></em> function is called when the request is done. It should match the following prototype: <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"> void callback(mixed $data, int $result[, resource $req]);</span> </code></div></div> <dl> <dt> <span class="term"><em><code class="parameter">data</code></em></span> <dd> <p class="para">is custom data passed to the request.</p></dd> </dt> <dt> <span class="term"><em><code class="parameter">result</code></em></span> <dd> <p class="para">request-specific result value; basically, the value returned by corresponding system call.</p></dd> </dt> <dt> <span class="term"><em><code class="parameter">req</code></em></span> <dd> <p class="para">is optional request resource which can be used with functions like <span class="function"><a href="function.eio-get-last-error.html" class="function">eio_get_last_error()</a></span></p></dd> </dt> </dl> </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">data</code></em></span> <dd> <p class="para"> Arbitrary variable passed to <em><code class="parameter">callback</code></em>. </p> </dd> </dt> </dl> </div> <div class="refsect1 returnvalues" id="refsect1-function.eio-open-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> <span class="function"><strong>eio_open()</strong></span> returns file descriptor in <em><code class="parameter">result</code></em> argument of <em><code class="parameter">callback</code></em> on success; otherwise, <em><code class="parameter">result</code></em> is equal to <strong><code>-1</code></strong>. </p> </div> <div class="refsect1 examples" id="refsect1-function.eio-open-examples"> <h3 class="title">Examples</h3> <div class="example" id="example-3599"> <p><strong>Example #1 <span class="function"><strong>eio_open()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$temp_filename </span><span style="color: #007700">= </span><span style="color: #DD0000">"eio-temp-file.tmp"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/* Is called when eio_close() finishes */<br /></span><span style="color: #007700">function </span><span style="color: #0000BB">my_close_cb</span><span style="color: #007700">(</span><span style="color: #0000BB">$data</span><span style="color: #007700">, </span><span style="color: #0000BB">$result</span><span style="color: #007700">) {<br /> </span><span style="color: #FF8000">// Zero indicates success<br /> </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$result </span><span style="color: #007700">== </span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /> @</span><span style="color: #0000BB">unlink</span><span style="color: #007700">(</span><span style="color: #0000BB">$data</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #FF8000">/* Is called when eio_open() finishes */<br /></span><span style="color: #007700">function </span><span style="color: #0000BB">my_file_opened_callback</span><span style="color: #007700">(</span><span style="color: #0000BB">$data</span><span style="color: #007700">, </span><span style="color: #0000BB">$result</span><span style="color: #007700">) {<br /> </span><span style="color: #FF8000">// $result should contain the file descriptor<br /> </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$result </span><span style="color: #007700">> </span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /><br /> if (</span><span style="color: #0000BB">$result </span><span style="color: #007700">> </span><span style="color: #0000BB">0</span><span style="color: #007700">) {<br /> </span><span style="color: #FF8000">// Close the file<br /> </span><span style="color: #0000BB">eio_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">, </span><span style="color: #0000BB">EIO_PRI_DEFAULT</span><span style="color: #007700">, </span><span style="color: #DD0000">"my_close_cb"</span><span style="color: #007700">, </span><span style="color: #0000BB">$data</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">eio_event_loop</span><span style="color: #007700">();<br /> }<br />}<br /><br /></span><span style="color: #FF8000">// Create new file for reading and writing<br />// Deny group and others to do anything with that file<br /></span><span style="color: #0000BB">eio_open</span><span style="color: #007700">(</span><span style="color: #0000BB">$temp_filename</span><span style="color: #007700">, </span><span style="color: #0000BB">EIO_O_CREAT </span><span style="color: #007700">| </span><span style="color: #0000BB">EIO_O_RDWR</span><span style="color: #007700">, </span><span style="color: #0000BB">EIO_S_IRUSR </span><span style="color: #007700">| </span><span style="color: #0000BB">EIO_S_IWUSR</span><span style="color: #007700">,<br /> </span><span style="color: #0000BB">EIO_PRI_DEFAULT</span><span style="color: #007700">, </span><span style="color: #DD0000">"my_file_opened_callback"</span><span style="color: #007700">, </span><span style="color: #0000BB">$temp_filename</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">eio_event_loop</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output something similar to:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> bool(true) bool(true) </pre></div> </div> </div> </div> <div class="refsect1 seealso" id="refsect1-function.eio-open-seealso"> <h3 class="title">See Also</h3> <ul class="simplelist"> <li class="member">eio_mknod</li> </ul> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.eio-nthreads.html">eio_nthreads</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.eio-poll.html">eio_poll</a></div> <div class="up"><a href="ref.eio.html">Eio Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>