mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 08:58:56 +00:00
Add: warning about semaphore permissions
Add: basic information and precautions on the introduction page Fix: file paths in examples Fix: eio_futime proto git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@317986 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
fc4d7aec84
commit
99ce1d3e88
11 changed files with 175 additions and 73 deletions
|
@ -11,8 +11,95 @@
|
|||
This extension provides asyncronous POSIX I/O by means of <link
|
||||
xlink:href="&url.eio.libeio;">libeio</link> C
|
||||
library written by Marc Lehmann.
|
||||
</para>
|
||||
|
||||
¬e.no-windows.extension;
|
||||
|
||||
<para>
|
||||
|
||||
<warning>
|
||||
<simpara>
|
||||
It is important to aware that each request is executed in a thread, and the
|
||||
order of execution of continuously queued requests basically is
|
||||
unpredictable. For instance, the following piece of code is incorrect.
|
||||
</simpara>
|
||||
</warning>
|
||||
|
||||
<example>
|
||||
<title>Incorrect requests</title>
|
||||
<programlisting role="php"><![CDATA[
|
||||
<?php
|
||||
// Request to create symlink of $filename to $link
|
||||
eio_symlink($filename, $link);
|
||||
|
||||
// Request to move $filename to $new_filename
|
||||
eio_rename($filename, $new_filename);
|
||||
|
||||
// Process requests
|
||||
eio_event_loop();
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
In the example above <function>eio_rename</function> request may finish
|
||||
before <function>eio_symlink</function>. To fix it you might call <function>eio_rename</function>
|
||||
in the callback of <function>eio_symlink</function>:
|
||||
<example>
|
||||
<title>Calling request from a request callback</title>
|
||||
<programlisting role="php"><![CDATA[
|
||||
<?php
|
||||
function my_symlink_done($filename, $result) {
|
||||
// Request to move $filename to $new_filename
|
||||
eio_rename($filename, "/path/to/new-name");
|
||||
|
||||
// Process requests
|
||||
eio_event_loop();
|
||||
}
|
||||
|
||||
// Request to create symlink of $filename to $link
|
||||
eio_symlink($filename, $link, EIO_PRI_DEFAULT, "my_symlink_done", $filename);
|
||||
|
||||
// Process requests
|
||||
eio_event_loop();
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
Alternatively, you might want to create a request group:
|
||||
<example>
|
||||
<title>Calling request from a request callback</title>
|
||||
<programlisting role="php"><![CDATA[
|
||||
<?php
|
||||
/* Is called when the group requests are done */
|
||||
function my_grp_done($data, $result) {
|
||||
// ...
|
||||
}
|
||||
|
||||
function my_symlink_done($filename, $result) {
|
||||
// Create eio_rename request and add it to the group
|
||||
$req = eio_rename($filename, "/path/to/new-name");
|
||||
eio_grp_add($grp, $req);
|
||||
// You might want to add more requests...
|
||||
}
|
||||
|
||||
// Create a request group
|
||||
$grp = eio_grp("my_grp_done", "my_grp_data");
|
||||
|
||||
// Create eio_symlink request and add it to the group
|
||||
// Pass $filename to the callback
|
||||
$req = eio_symlink($filename, $link,
|
||||
EIO_PRI_DEFAULT, "my_symlink_done", $filename);
|
||||
eio_grp_add($grp, $req);
|
||||
|
||||
// Process requests
|
||||
eio_event_loop();
|
||||
?>
|
||||
]]></programlisting>
|
||||
</example>
|
||||
Group is a special kind of request that could accumulate a set of regular
|
||||
<emphasis>eio</emphasis> requests. This could be used to create a complex
|
||||
request that opens, reads and closes a file.
|
||||
|
||||
</para>
|
||||
</preface>
|
||||
<!--}}}-->
|
||||
|
|
|
@ -29,6 +29,10 @@
|
|||
their defaults.
|
||||
</para>
|
||||
|
||||
<warning><simpara>Be sure that you gave read
|
||||
and write permissions for the Web server user or group(according to the file
|
||||
system setup). Otherwise, the internal event loop will fail.</simpara></warning>
|
||||
|
||||
</section>
|
||||
|
||||
<!-- Keep this comment at the end of the file
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
<?php
|
||||
/* Is called when eio_nop() finished */
|
||||
function my_nop_cb($data, $result) {
|
||||
echo "my_nop, ", $data, "\n";
|
||||
echo "my_nop ", $data, "\n";
|
||||
}
|
||||
|
||||
// This eio_nop() call will be cancelled
|
||||
|
@ -22,7 +22,7 @@ eio_cancel($req);
|
|||
// This time eio_nop() will be processed
|
||||
eio_nop(EIO_PRI_DEFAULT, "my_nop_cb", "2");
|
||||
|
||||
// Process enqueued eio_* calls
|
||||
// Process requests
|
||||
eio_event_loop();
|
||||
?>
|
||||
]]>
|
||||
|
@ -128,7 +128,7 @@ int(1001)
|
|||
* Create a group request to open, read and close a file
|
||||
*/
|
||||
|
||||
$temp_filename = "eio-file.tmp";
|
||||
$temp_filename = dirname(__FILE__) ."/eio-file.tmp";
|
||||
$fp = fopen($temp_filename, "w");
|
||||
fwrite($fp, "some data");
|
||||
fclose($fp);
|
||||
|
@ -148,7 +148,7 @@ function my_grp_file_opened_callback($data, $result) {
|
|||
|
||||
var_dump($result > 0);
|
||||
|
||||
// Enqueue eio_read()
|
||||
// Create eio_read() request and add it to the group
|
||||
$req = eio_read($my_file_fd, 4, 0, EIO_PRI_DEFAULT, "my_grp_file_read_callback");
|
||||
eio_grp_add($grp, $req);
|
||||
}
|
||||
|
@ -159,16 +159,16 @@ function my_grp_file_read_callback($data, $result) {
|
|||
|
||||
var_dump($result);
|
||||
|
||||
// Create eio_close() request and add it to the group
|
||||
$req = eio_close($my_file_fd);
|
||||
|
||||
// Enqueue eio_close()
|
||||
eio_grp_add($grp, $req);
|
||||
}
|
||||
|
||||
$grp = eio_grp("my_grp_done", "my_grp_data");
|
||||
|
||||
// Enqueue eio_open()
|
||||
$req = eio_open($temp_filename, EIO_O_RDWR | EIO_O_APPEND , NULL, 0, "my_grp_file_opened_callback", NULL);
|
||||
// Create eio_open() request and add it to the group
|
||||
$req = eio_open($temp_filename, EIO_O_RDWR | EIO_O_APPEND , NULL,
|
||||
EIO_PRI_DEFAULT, "my_grp_file_opened_callback", NULL);
|
||||
eio_grp_add($grp, $req);
|
||||
var_dump($grp);
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@
|
|||
<?php
|
||||
/* Is called when eio_nop() finished */
|
||||
function my_nop_cb($data, $result) {
|
||||
echo "my_nop, ", $data, "\n";
|
||||
echo "my_nop ", $data, "\n";
|
||||
}
|
||||
|
||||
// This eio_nop() call will be cancelled
|
||||
|
@ -80,7 +80,7 @@ eio_cancel($req);
|
|||
// This time eio_nop() will be processed
|
||||
eio_nop(EIO_PRI_DEFAULT, "my_nop_cb", "2");
|
||||
|
||||
// Process enqueued eio_* calls
|
||||
// Process requests
|
||||
eio_event_loop();
|
||||
?>
|
||||
]]>
|
||||
|
|
|
@ -72,7 +72,7 @@
|
|||
<![CDATA[
|
||||
<?php
|
||||
// Create temporary file
|
||||
$tmp_filename = "eio-file.tmp";
|
||||
$tmp_filename = dirname(__FILE__) ."/eio-file.tmp";
|
||||
touch($tmp_filename);
|
||||
|
||||
/* Is called when eio_fstat() done */
|
||||
|
|
|
@ -10,13 +10,17 @@
|
|||
<refsect1 role="description">
|
||||
&reftitle.description;
|
||||
<methodsynopsis>
|
||||
<type>ReturnType</type><methodname>eio_futime</methodname>
|
||||
<methodparam><type>string</type><parameter>fd</parameter></methodparam>
|
||||
<methodparam><type>string</type><parameter>atime</parameter></methodparam>
|
||||
<methodparam><type>string</type><parameter>mtime</parameter></methodparam>
|
||||
<methodparam choice="opt"><type>string</type><parameter>pri</parameter></methodparam>
|
||||
<methodparam choice="opt"><type>string</type><parameter>callback</parameter></methodparam>
|
||||
<methodparam choice="opt"><type>string</type><parameter>data</parameter></methodparam>
|
||||
<type>resource</type><methodname>eio_futime</methodname>
|
||||
<methodparam><type>int</type><parameter>fd</parameter></methodparam>
|
||||
<methodparam><type>int</type><parameter>atime</parameter></methodparam>
|
||||
<methodparam><type>int</type><parameter>mtime</parameter></methodparam>
|
||||
<methodparam
|
||||
choice="opt"><type>int</type><parameter>pri</parameter><initializer>EIO_PRI_DEFAULT</initializer></methodparam>
|
||||
<methodparam
|
||||
choice="opt"><type>mixed</type><parameter>callback</parameter><initializer>NULL</initializer></methodparam>
|
||||
<methodparam
|
||||
choice="opt"><type>mixed</type><parameter>data</parameter><initializer>NULL</initializer></methodparam>
|
||||
|
||||
</methodsynopsis>
|
||||
<para>
|
||||
<function>eio_futime</function> changes file last access and modification
|
||||
|
|
|
@ -53,68 +53,72 @@
|
|||
&reftitle.examples;
|
||||
<example>
|
||||
<title>Grouping requests</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
/*
|
||||
* Create a group request to open, read and close a file
|
||||
*/
|
||||
<programlisting role="php"><![CDATA[
|
||||
<?php
|
||||
/*
|
||||
* Create a group request to open, read and close a file
|
||||
*/
|
||||
|
||||
$temp_filename = "eio-file.tmp";
|
||||
$fp = fopen($temp_filename, "w");
|
||||
fwrite($fp, "some data");
|
||||
fclose($fp);
|
||||
// Create temporary file and write some bytes to it
|
||||
$temp_filename = dirname(__FILE__) ."/eio-file.tmp";
|
||||
$fp = fopen($temp_filename, "w");
|
||||
fwrite($fp, "some data");
|
||||
fclose($fp);
|
||||
|
||||
/* Is called when the group requests are done */
|
||||
function my_grp_done($data, $result) {
|
||||
global $temp_filename;
|
||||
var_dump($result == 0);
|
||||
@unlink($temp_filename);
|
||||
}
|
||||
/* Is called when the group requests are done */
|
||||
function my_grp_done($data, $result) {
|
||||
var_dump($result == 0);
|
||||
@unlink($data);
|
||||
}
|
||||
|
||||
/* Is called when eio_open() done */
|
||||
function my_grp_file_opened_callback($data, $result) {
|
||||
global $my_file_fd, $grp;
|
||||
/* Is called when eio_open() done */
|
||||
function my_grp_file_opened_callback($data, $result) {
|
||||
global $grp;
|
||||
|
||||
$my_file_fd = $result;
|
||||
// $result should contain the file descriptor
|
||||
var_dump($result > 0);
|
||||
|
||||
var_dump($result > 0);
|
||||
// Create eio_read() request and add it to the group
|
||||
// Pass file descriptor to the callback
|
||||
$req = eio_read($result, 4, 0,
|
||||
EIO_PRI_DEFAULT, "my_grp_file_read_callback", $result);
|
||||
eio_grp_add($grp, $req);
|
||||
}
|
||||
|
||||
// Enqueue eio_read()
|
||||
$req = eio_read($my_file_fd, 4, 0, EIO_PRI_DEFAULT, "my_grp_file_read_callback");
|
||||
eio_grp_add($grp, $req);
|
||||
}
|
||||
/* Is called when eio_read() done */
|
||||
function my_grp_file_read_callback($data, $result) {
|
||||
global $grp;
|
||||
|
||||
/* Is called when eio_read() done */
|
||||
function my_grp_file_read_callback($data, $result) {
|
||||
global $my_file_fd, $grp;
|
||||
// Read bytes
|
||||
var_dump($result);
|
||||
|
||||
var_dump($result);
|
||||
// Create eio_close() request and add it to the group
|
||||
// $data should contain the file descriptor
|
||||
$req = eio_close($data);
|
||||
eio_grp_add($grp, $req);
|
||||
}
|
||||
|
||||
$req = eio_close($my_file_fd);
|
||||
// Create request group
|
||||
$grp = eio_grp("my_grp_done", $temp_filename);
|
||||
var_dump($grp);
|
||||
|
||||
// Enqueue eio_close()
|
||||
eio_grp_add($grp, $req);
|
||||
}
|
||||
// Create eio_open() request and add it to the group
|
||||
$req = eio_open($temp_filename, EIO_O_RDWR | EIO_O_APPEND , NULL,
|
||||
EIO_PRI_DEFAULT, "my_grp_file_opened_callback", NULL);
|
||||
eio_grp_add($grp, $req);
|
||||
|
||||
$grp = eio_grp("my_grp_done", "my_grp_data");
|
||||
|
||||
// Enqueue eio_open()
|
||||
$req = eio_open($temp_filename, EIO_O_RDWR | EIO_O_APPEND , NULL, 0, "my_grp_file_opened_callback", NULL);
|
||||
eio_grp_add($grp, $req);
|
||||
var_dump($grp);
|
||||
|
||||
eio_event_loop();
|
||||
?>
|
||||
]]></programlisting>
|
||||
// Process requests
|
||||
eio_event_loop();
|
||||
?>
|
||||
]]></programlisting>
|
||||
&example.outputs.similar;
|
||||
<screen><![CDATA[
|
||||
resource(6) of type (EIO Group Descriptor)
|
||||
bool(true)
|
||||
string(4) "some"
|
||||
bool(true)
|
||||
]]></screen>
|
||||
</example>
|
||||
<screen><![CDATA[
|
||||
resource(6) of type (EIO Group Descriptor)
|
||||
bool(true)
|
||||
string(4) "some"
|
||||
bool(true)
|
||||
]]></screen>
|
||||
</example>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="seealso">
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$temp_filename = "eio-file.tmp";
|
||||
$temp_filename = dirname(__FILE__) ."/eio-file.tmp";
|
||||
$fp = fopen($temp_filename, "w");
|
||||
fwrite($fp, "some data");
|
||||
fclose($fp);
|
||||
|
|
|
@ -72,7 +72,7 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$tmp_filename = "eio-file.tmp";
|
||||
$tmp_filename = dirname(__FILE__). "/eio-file.tmp";
|
||||
touch($tmp_filename);
|
||||
|
||||
function my_res_cb($data, $result) {
|
||||
|
|
|
@ -34,7 +34,11 @@
|
|||
<term><parameter>path</parameter></term>
|
||||
<listitem>
|
||||
<para>
|
||||
|
||||
Path of the file to be opened.
|
||||
<warning><simpara>
|
||||
In some SAPIs(e.g. <emphasis>PHP-FPM</emphasis>) it could fail, if you
|
||||
don't specify full path.
|
||||
</simpara></warning>
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
@ -42,7 +46,7 @@
|
|||
<term><parameter>flags</parameter></term>
|
||||
<listitem>
|
||||
<para>One of <emphasis>EIO_O_*</emphasis> constants, or their
|
||||
combinations. <emphasis>EIO_O_*</emphasis> constants have the same
|
||||
combinations. <emphasis>EIO_O_*</emphasis> constants have the same
|
||||
meaning, as their corresponding <emphasis>O_*</emphasis> counterparts
|
||||
defined in <literal>fnctl.h</literal> C header file. Default is
|
||||
<constant>EIO_O_RDWR</constant>.
|
||||
|
|
|
@ -81,7 +81,6 @@
|
|||
<title><function>eio_rename</function> example</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
<?php
|
||||
$filename = dirname(__FILE__)."/eio-temp-file.dat";
|
||||
touch($filename);
|
||||
|
|
Loading…
Reference in a new issue