return $this->attempts; } /* this method overwrites thread data */ protected function setData($data) { $this->data = $data; } /* this method reads and writes thread data */ protected function addData($data) { $this->data = array_merge($this->data, $data); } /* this method reads data but makes no changes, doesnt usually happen in the real world */ protected function getData() { return $this->data; } } $worker = new ExampleWorker("My Worker Thread"); $work = array(); while ($i++ < 10) { printf("Stacking: %d/%d\n", $i, $worker->stack($work[] = new Work(array(rand() * 100)))); } $worker->start(); usleep(10000); while ($i++ < 20) { printf("Stacking: %d/%d\n", $i, $worker->stack($work[] = new Work(array(rand() * 100)))); } $worker->shutdown(); printf("Result: %d/%d\n", $worker->getAttempts(), $worker->getStacked()); print_r($worker->getData());
/* this method overwrites thread data */ protected function setData($data) { $this->data = $data; } /* this method reads and writes thread data */ protected function addData($data) { $this->data = array_merge($this->data, $data); } /* this method reads data but makes no changes, doesnt usually happen in the real world */ protected function getData() { return $this->data; } } $worker = new ExampleWorker("My Worker Thread"); $work = array(); while ($i++ < 10) { $work[$i] = new Work(array(rand() * 100)); printf("Stacking: %d/%d\n", $i, $worker->stack($work[$i])); } $worker->start(); usleep(10000); while ($i++ < 20) { $work[$i] = new Work(array(rand() * 100)); printf("Stacking: %d/%d\n", $i, $worker->stack($work[$i])); } $worker->shutdown(); printf("Result: %d/%d\n", $worker->getAttempts(), $worker->getStacked()); print_r($worker->getData());