public $data = []; public function run() { echo 'Running ' . $this->getStacked() . ' jobs' . PHP_EOL; } /** * To avoid corrupting the array here * we use array_merge here instead of just * $this->data[] = $html * * @param string $data */ public function addData($data) { $this->data = array_merge($this->data, [$data]); } } // Stack our jobs on our worker $worker = new Searcher(); $searches = ['dogs', 'cats', 'birds']; foreach ($searches as $key => &$search) { $search = new SearchGoogle($search); $worker->stack($search); } // Start all jobs $worker->start(); // Join all jobs and close worker $worker->shutdown(); foreach ($worker->data as $html) { echo substr($html, 0, 20) . PHP_EOL; }