Created
December 2, 2014 16:41
-
-
Save flavioheleno/327396fc3a75f8723a4a to your computer and use it in GitHub Desktop.
PHP PThreads and TimeZone
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 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