Created
July 2, 2009 18:16
-
-
Save pstengel/139616 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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