Skip to content

Instantly share code, notes, and snippets.

@abdullah353
Created August 20, 2014 11:16
Show Gist options
  • Save abdullah353/8a7ff9432100d37a38a7 to your computer and use it in GitHub Desktop.
Save abdullah353/8a7ff9432100d37a38a7 to your computer and use it in GitHub Desktop.
#!/usr/bin/php
<?php
class AsyncOperation extends Thread {
public function __construct($arg) {
$this->arg = $arg;
}
public function run() {
if ($this->arg) {
$sleep = mt_rand(1, 10);
printf('%s: %s -start -sleeps %d' . "\n", date("g:i:sa"), $this->arg, $sleep);
sleep($sleep);
printf('%s: %s -finish' . "\n", date("g:i:sa"), $this->arg);
}
}
}
// Create a array
$stack = array();
//Iniciate Miltiple Thread
foreach ( range("A", "D") as $i ) {
$stack[] = new AsyncOperation($i);
}
// Start The Threads
foreach ( $stack as $t ) {
$t->start();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment