Home >Backend Development >PHP Tutorial >PHP pthreads学习笔记

PHP pthreads学习笔记

WBOY
WBOYOriginal
2016-06-23 13:17:291062browse

最近在学习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 }

 

Statement:
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