command = $command; } public function rewind() { $this->stream = popen($this->command, 'r'); $this->iteration = 0; } public function current() { return fgets($this->stream); } public function key() { return $this->iteration; } public function next() { $this->iteration++; } public function valid() { return !feof($this->stream); } } $processIterator = new ProcessIterator(__DIR__ . '/tmpeee.sh'); foreach ($processIterator as $i => $result) { echo "$i Time : " .(microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"]) . ", result : " . $result . "\n"; if ($i == 9) { echo "php sleeping for 8\n"; sleep(8); } }