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"; } } $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";