Created
October 18, 2012 14:27
-
-
Save fd00/3912212 to your computer and use it in GitHub Desktop.
ThreadExample.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ThreadExample extends Thread | |
{ | |
public function run() | |
{ | |
$id = $this->getThreadId(); | |
printf("ID[%d] : start & sleep\n", $id); | |
sleep($id % 10); | |
printf("ID[%d] : done\n", $id); | |
} | |
static public function main() | |
{ | |
$threads = array(); | |
for ($i=0; $i<10; $i++) { | |
$thread = new ThreadExample(); | |
$thread->start(); | |
$threads[] = $thread; | |
} | |
} | |
} | |
ThreadExample::main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment