Skip to content

Instantly share code, notes, and snippets.

@flavioheleno
Created December 2, 2014 16:41
Show Gist options
  • Save flavioheleno/327396fc3a75f8723a4a to your computer and use it in GitHub Desktop.
Save flavioheleno/327396fc3a75f8723a4a to your computer and use it in GitHub Desktop.
PHP PThreads and TimeZone
<?php
class ThreadParent {
public function __construct() {
date_default_timezone_set('UTC');
}
public function breed() {
echo 'Starting..', PHP_EOL;
$threads = array();
for ($i = 0; $i < 5; $i++) {
$thread = new ThreadChild;
$thread->start();
$threads[] = $thread;
}
foreach ($threads as $thread)
$thread->join();
echo 'Done!', PHP_EOL;
}
}
class ThreadChild extends Thread {
public function run() {
sleep(1);
echo date('d/m/Y H:i:s'), PHP_EOL;
}
}
$parent = new ThreadParent;
$parent->breed();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment