码迷,mamicode.com
首页 > 编程语言 > 详细

php实现多线程

时间:2018-04-14 11:11:41      阅读:198      评论:0      收藏:0      [点我收藏+]

标签: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实现多线程

    标签:php实现多进程

    原文地址:http://blog.51cto.com/12173069/2103329

    (0)
    (0)
       
    举报
    评论 一句话评论(0
    登录后才能评论!
    © 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
    迷上了代码!