PHP pthreads学习笔记

WBOY
Release: 2016-06-23 13:17:29
Original
1043 people have browsed it

最近在学习PHP pthreads,把学习笔记

 

 

 一般都是用主线程来控制各个子线程的。

1. 开启多个线程并发执行。

 1 <?php 2 class HelloWorld extends Thread { 3 public function __construct($world) { 4 $this->world = $world; 5  } 6 7 public function run() { 8 print_r(sprintf("Hello %s\n", $this->world)); 9 sleep(1);10  }11 }1213 for ($i=0; $i<10; $i++) {14 $pool[] = new HelloWorld('world' . $i);15 }1617 foreach ($pool as $work) {18 $work->start();19 }
Copy after login

 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template