php实现多线程
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php实现多线程相关的知识,希望对你有一定的参考价值。
- 代码:
<?php for ($i = 1; $i <= 5; $i++) { $pid = pcntl_fork(); if (!$pid) { print "In child $i\n"; exit($i); } } while (pcntl_waitpid(0, $status) != -1) { $status = pcntl_wexitstatus($status); echo "Child $status completed\n"; }
- 输出:
In child 4 Child 4 completed In child 1 Child 1 completed In child 2 Child 2 completed In child 3 Child 3 completed In child 5 Child 5 completed
以上是关于php实现多线程的主要内容,如果未能解决你的问题,请参考以下文章