note 41244 deleted from function.proc-open by nlopess
| From: | nlopess@php.net | Date: | Sun, 04 Apr 2004 11:07:29 +0000 |
| Subject: | note 41244 deleted from function.proc-open by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-67618@lists.php.net to get a copy of this message | ||
Note Submitter: val@pack.homelinux.com
----
i used for multithreading
i needed to ping large number of hosts
i open all the process, then i read and close them.
<?php
//(...) part of the code
for ($oo=$Dep; $oo<$var; $oo++) { // i open the process $var is the number of process
$descriptorspec[$oo] = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("file", "/tmp/error-output.txt", "a"),
);
$ip = getip(....); // internal function make your own =)
$process[$oo] = proc_open("ping -c 3 -w 20 $ip", $descriptorspec[$oo],
$pipes[$oo]);
}
sleep(3);
for ($oo2=$Dep2; $oo2<$var2; $oo2++) {
if (is_resource($process[$oo2])) {
while(!feof($pipes[$oo2][1])) {
$cont[$oo2] .= fgets($pipes[$oo2][1] ); // i read the process output
}
fclose($pipes[$oo2][1]);
$con[$oo2] = proc_close($process[$oo2]); // i close all one by one
}
}
//(...) parf of the code
?>