进程控制
简介
PHP 的进程控制支持实现了 Unix 方式的进程创建, 程序执行, 信号处理以及进程的中断。进程控制不能被应用在 Web 服务器环境,当其被用于 Web 服务环境时可能会带来意外的结果。
这份文档用于阐述每个进程控制函数的通常用法。关于 Unix 进程控制的更多信息建议查阅系统文档中关于 fork(2)、waitpid(2)、signal(2)等的部分或更全面的参考资料比如《Unix 环境高级编程》(作者:W. Richard Stevens、Addison-Wesley 出版)。
PCNTL 现在使用了 ticks 作为信号处理的回调机制,ticks 在速度上远远超过了之前的处理机制。这个变化与“用户 ticks”遵循了相同的语义。您可以使用 declare() 语句在程序中指定允许发生回调的位置。这使得我们对异步事件处理的开销最小化。在编译 PHP 时启用 pcntl 将始终承担这种开销,不论脚本中是否真正使用了 pcntl。
注意:
此扩展在 Windows 平台上不可用。
- 安装/配置
- 预定义常量
- 示例
- Pcntl\QosClass — The Pcntl\QosClass Enum
- PCNTL 函数
- pcntl_alarm — 为进程设置 alarm 闹钟信号
- pcntl_async_signals — Enable/disable asynchronous signal handling or return the old setting
- pcntl_errno — 别名 pcntl_get_last_error
- pcntl_exec — 在当前进程空间执行指定程序
- pcntl_fork — 在当前进程当前位置产生分叉(fork)
- pcntl_forkx — Create a child process using forkx(2)
- pcntl_get_last_error — Retrieve the error number set by the last pcntl function which failed
- pcntl_getcpu — Get the CPU number on which the calling process last executed
- pcntl_getcpuaffinity — Get the cpu affinity of a process
- pcntl_getpriority — 获取任意进程的优先级
- pcntl_getqos_class — Get the QoS class of the current thread
- pcntl_rfork — Manipulates process resources
- pcntl_setcpuaffinity — Set the cpu affinity of a process
- pcntl_setns — Reassociate the calling process with a namespace of another process
- pcntl_setpriority — 修改任意进程的优先级
- pcntl_setqos_class — Set the QoS class of the current thread
- pcntl_signal — 安装信号处理程序
- pcntl_signal_dispatch — 调用等待信号的处理程序
- pcntl_signal_get_handler — Get the current handler for specified signal
- pcntl_sigprocmask — 设置或检索阻塞信号
- pcntl_sigtimedwait — 带超时机制的信号等待
- pcntl_sigwaitinfo — 等待信号
- pcntl_strerror — Retrieve the system error message associated with the given errno
- pcntl_unshare — Dissociates parts of the process execution context
- pcntl_wait — 等待或返回 fork 的子进程状态
- pcntl_waitid — 等待子进程改变状态
- pcntl_waitpid — 等待或返回 fork 的子进程状态
- pcntl_wexitstatus — 返回一个中断的子进程的返回代码
- pcntl_wifcontinued — Checks whether the child process has continued from a job control stop
- pcntl_wifexited — 检查状态代码是否代表一个正常的退出
- pcntl_wifsignaled — 检查子进程状态码是否代表由于某个信号而中断
- pcntl_wifstopped — 检查子进程当前是否已经停止
- pcntl_wstopsig — 返回导致子进程停止的信号
- pcntl_wtermsig — 返回导致子进程中断的信号
来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。
