Skip to content

Instantly share code, notes, and snippets.

@fd00
Created October 18, 2012 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fd00/3912212 to your computer and use it in GitHub Desktop.
Save fd00/3912212 to your computer and use it in GitHub Desktop.
ThreadExample.php
<?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