Skip to content

Instantly share code, notes, and snippets.

@pstengel
Created July 2, 2009 18:16
Show Gist options
  • Save pstengel/139616 to your computer and use it in GitHub Desktop.
Save pstengel/139616 to your computer and use it in GitHub Desktop.
<?php
declare(ticks = 1);
class HRServerMon_Poller
{
var $hostname;
function HRServerMon_Poller($hostname)
{
if ($hostname == "host7.hrwebservices.net")
sleep(5);
else
sleep(2);
$this->hostname = $hostname;
echo $this->hostname . "\n";
}
}
$children = 0;
$servers = file("servers");
for ($i = 0; $i < 5; $i++) {
$server = trim(array_pop($servers));
$children++;
$pid = pcntl_fork();
if (!$pid) {
echo "Child executed. There are $children running.\n";
$poll = new HRServerMon_Poller($server);
exit(0);
}
}
while (1) {
while (pcntl_waitpid(0, $status) != -1) {
$children--;
echo "Child exited. There are $children running.\n";
if (count($servers)) {
$server = trim(array_pop($servers));
$children++;
$pid = pcntl_fork();
if (!$pid) {
echo "Child executed. There are $children running.\n";
$poll = new HRServerMon_Poller($server);
exit(0);
}
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment