Last active
November 2, 2016 19:37
-
-
Save hiend/53c2a8e554957a85746f to your computer and use it in GitHub Desktop.
Revisions
-
hiend revised this gist
May 3, 2014 . 1 changed file with 6 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -29,13 +29,16 @@ public function run() } } $threads = array(); $thread_count = 8; $start_time = microtime(true); while($thread_count--) { $threads[$thread_count] = new hashThread(rand(10000, 100000), $thread_count); $threads[$thread_count]->start(PTHREADS_INHERIT_NONE); } array_map(function($thread) { $thread->join(); }, $threads); echo "Done in: " . round(microtime(true) - $start_time, 2) . " seconds\r\n"; -
hiend created this gist
May 3, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ <?php class hashThread extends Thread { private $max = 1; private $index = 0; function __construct($max, $index) { $this->max = $max; $this->index = $index; } public function run() { if (in_array($this->index, [2,4,6,8])) { require 'null'; } if (in_array($this->index, [7])) { throw Exception("stop"); } for ($i=1; $i<=$this->max; $i++) { md5($i); } echo "Thread #{$this->index} finished\r\n"; } } $thread_count = 8; $start_time = microtime(true); for($i=1; $i<=$thread_count; $i++) { $thread[$i] = new hashThread(rand(10000, 100000), $i); $thread[$i]->start(PTHREADS_INHERIT_NONE); } echo "Done in: " . round(microtime(true) - $start_time, 2) . " seconds\r\n";