1
0
mirror of https://github.com/php/doc-zh.git synced 2026-03-24 15:12:20 +01:00
Files

131 lines
5.2 KiB
XML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 57c7669a1f5336cb17413e0b46540c52c77ee84f Maintainer: mowangjuanzi Status: ready -->
<!-- CREDITS: Luffy -->
<book xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" xml:id="book.parallel">
<?phpdoc extension-membership="pecl" ?>
<title>parallel</title>
<titleabbrev>parallel</titleabbrev>
<preface xml:id="intro.parallel">
&reftitle.intro;
<simpara>
parallel 是适用于 PHP ≥ 7.2.0 的并行并发扩展。自 parallel 1.2.0 起,要求 PHP ≥ 8.0.0。
</simpara>
<simpara>
下面是并行核心概念的简要描述,更多详细信息可以在手册的这一节中找到。
</simpara>
<simplesect>
<title>Runtime</title>
<simpara>
<classname>parallel\Runtime</classname> 表示 PHP 解释器线程。将可选的 bootstrap 文件传递给 <methodname>parallel\Runtime::__construct</methodname>
可用于配置 <classname>parallel\Runtime</classname>,这通常是自动加载器或者一些其它预加载程序:引导文件将在任何任务执行之前加载。
</simpara>
<simpara>
构造之后,<classname>parallel\Runtime</classname> 在 PHP 对象正常作用域规则关闭、杀死或者销毁之前一直可用。<methodname>parallel\Runtime::run</methodname>
允许程序员安排并行执行的任务。<classname>parallel\Runtime</classname> 有 FIFO 调度,任务将按照调度的顺序执行。
</simpara>
</simplesect>
<simplesect>
<title>功能性 API</title>
<simpara>
Parallel 在 <classname>parallel\Runtime</classname> 之上实现了一个功能性的、更高级别的 API提供了单一函数入口点来通过自动调度执行并行代码<function>parallel\run</function>
</simpara>
</simplesect>
<simplesect>
<title>Task</title>
<para>
Task 只是用于并行执行的 <classname>Closure</classname><classname>Closure</classname> 几乎可以包含任何指令,包含嵌套闭包。但是 task
中禁止使用一些指令:
<itemizedlist>
<listitem>
<simpara>yield</simpara>
</listitem>
<listitem>
<simpara>使用引用</simpara>
</listitem>
<listitem>
<simpara>声明类</simpara>
</listitem>
<listitem>
<simpara>声明命名函数</simpara>
</listitem>
</itemizedlist>
</para>
<note>
<simpara>
嵌套闭包可以 yield 或使用引用,但不得包含类声明或命名函数声明。
</simpara>
</note>
<note>
<simpara>
Task 可能 include 的文件不禁止任何指令。
</simpara>
</note>
</simplesect>
<simplesect>
<title>Future</title>
<simpara>
<classname>parallel\Future</classname> 用于访问 task 的返回值,并公开用于取消任务的 API。
</simpara>
</simplesect>
<simplesect>
<title>Channel</title>
<simpara>
Task 可以通过参数调用,使用词法作用域变量(按值)和返回值(通过 <classname>parallel\Future</classname>),但这些仅允许单向通信:它们允许程序员将数据发送到
task 中并从 task 中检索数据,但不允许 task 之间进行双向通信。<classname>parallel\Channel</classname> API 允许 task
之间进行双向通信,<classname>parallel\Channel</classname> 是 task 之间类似套接字的链接,程序员可以用于发送和接收数据。
</simpara>
</simplesect>
<simplesect>
<title>Events</title>
<simpara>
<classname>parallel\Events</classname> API 实现了原生特性(<classname>Traversable</classname>)事件循环,和 <methodname>parallel\Events::poll</methodname>
方法。允许程序员使用 channel 和 future 组合。程序员只需将 channel 和 future 添加到事件循环中,可以选择使用 <methodname>parallel\Events::setInput</methodname> 设置用于写入的
input。然后进入 foreach当对象可用时parallel 将从这些对象中读取和写入数据,同时生成描述已经发生的操作的 <classname>parallel\Events\Event</classname> 对象。
</simpara>
</simplesect>
<simplesect role="seealso">
&reftitle.seealso;
<simplelist>
<member><xref linkend="philosophy.parallel"/></member>
</simplelist>
</simplesect>
</preface>
&reference.parallel.setup;
&reference.parallel.philosophy;
&reference.parallel.functional;
&reference.parallel.parallel.runtime;
&reference.parallel.parallel.future;
&reference.parallel.parallel.channel;
&reference.parallel.parallel.events;
&reference.parallel.parallel.events.input;
&reference.parallel.parallel.events.event;
&reference.parallel.parallel.events.event.type;
&reference.parallel.parallel.sync;
<!--&reference.parallel.examples;-->
</book>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->