#!/usr/bin/php array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w') ); $this->resource = proc_open($command, $descriptorspec, $this->pipes, null, $_ENV); } public function read() { if (is_resource($this->resource)) { $retval = ''; $error = ''; $stdin = $this->pipes[0]; $stdout = $this->pipes[1]; $stderr = $this->pipes[2]; while (! feof($stdout)) { $retval .= fgets($stdout); } while (! feof($stderr)) { $error .= fgets($stderr); } fclose($stdin); fclose($stdout); fclose($stderr); $exit_code = proc_close($this->resource); } if (! empty($error)) { throw new Exception($error); } else { return $retval; } } } $hosts[] = 'google.com'; $hosts[] = 'google.co.uk'; $hosts[] = 'google.it'; $hosts[] = 'google.fr'; $hosts[] = 'google.de'; foreach ($hosts AS $host) { // Fork commands; $procs[$host] = new Process; $procs[$host]->open('dig '.$host.''); } foreach ($hosts AS $host) { try { $output = $procs[$host]->read(); $pattern = "/$domain\.\s*[0-9]+\s*IN\s*A\s*([^\s]+)/i"; preg_match($pattern, $output, $matches); echo $host .' has ip '.$matches[1]."\n"; } catch (Exception $error) { echo $error->getMessage() . "\n"; } } ?>