大网数据广告活动
PHP 语言与运行手册

parallel\run · Execution

· 52CE 我爱测

Shall schedule task for execution in parallel.

parallel\run

(1.0.0)

parallel\run — Execution

说明

function parallel\run(Closure $task): ?Future

Shall schedule task for execution in parallel.

function parallel\run(Closure $task, array $argv): ?Future

Shall schedule task for execution in parallel, passing argv at execution time.

Automatic Scheduling

If a \parallel\Runtime internally created and cached by a previous call to parallel\run() is idle, it will be used to execute the task. If no \parallel\Runtime is idle parallel will create and cache a \parallel\Runtime.

注意:

\parallel\Runtime objects created by the programmer are not used for automatic scheduling.

参数

task

A Closure with specific characteristics.

argv

An array of arguments with specific characteristics to be passed to task at execution time.

Task Characteristics

Closures scheduled for parallel execution must not:

  • accept or return by reference
  • accept or return internal objects (see notes)
  • execute a limited set of instructions

Instructions prohibited in Closures intended for parallel execution are:

  • yield
  • use by-reference
  • declare class
  • declare named function

注意:

Nested closures may yield or use by-reference, but must not contain class or named function declarations.

注意:

No instructions are prohibited in the files which the task may include.

Arguments Characteristics

Arguments must not:

  • contain references
  • contain resources
  • contain internal objects (see notes)

注意:

In the case of file stream resources, the resource will be cast to the file descriptor and passed as int where possible, this is unsupported on Windows.

Internal Objects Notes

Internal objects generally use a custom structure which cannot be copied by value safely, PHP currently lacks the mechanics to do this (without serialization) and so only objects that do not use a custom structure may be shared.

Some internal objects do not use a custom structure, for example parallel\Events\Event and so may be shared.

Closures are a special kind of internal object and support being copied by value, and so may be shared.

Channels are central to writing parallel code and support concurrent access and execution by necessity, and so may be shared.

警告

A user class that extends an internal class may use a custom structure as defined by the internal class, in which case they cannot be copied by value safely, and so may not be shared.

返回值

警告

The return parallel\Future must not be ignored when the task contains a return or throw statement.

Exceptions

警告

Shall throw parallel\Runtime\Error\Closed if parallel\Runtime was closed.

警告

Shall throw parallel\Runtime\Error\IllegalFunction if task is a closure created from an internal function.

警告

Shall throw parallel\Runtime\Error\IllegalInstruction if task contains illegal instructions.

警告

Shall throw parallel\Runtime\Error\IllegalParameter if task accepts or argv contains illegal variables.

警告

Shall throw parallel\Runtime\Error\IllegalReturn if task returns illegally.

来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
PHP Documentation Group
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。