Skip to content

Instantly share code, notes, and snippets.

@travail
Created March 17, 2010 18:11
Show Gist options
  • Select an option

  • Save travail/335530 to your computer and use it in GitHub Desktop.

Select an option

Save travail/335530 to your computer and use it in GitHub Desktop.
<?php
set_include_path(dirname(__FILE__) . '/../lib');
require_once('Parallel/Prefork.php');
main();
exit();
function main()
{
$pp = new Parallel_Prefork(array(
'max_workers' => 5,
'trap_signals' => array(
SIGHUP => SIGTERM,
SIGTERM => SIGTERM,
),
));
while ($pp->signalReceived() !== SIGTERM) {
loadConfig();
if ($pp->start()) {
continue;
}
workChildren();
$pp->finish();
}
$pp->waitAllChildren();
}
function loadConfig()
{
echo "Load configuratioin\n";
}
function workChildren()
{
for ($i = 1; $i <= 3; $i++) {
echo "Sleep $i seconds\n";
sleep($i);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment