Skip to content

Instantly share code, notes, and snippets.

@imr
Created July 21, 2012 02:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imr/3154317 to your computer and use it in GitHub Desktop.
Save imr/3154317 to your computer and use it in GitHub Desktop.
Horde forked cli with database
#!/usr/bin/env php
<?php
$baseFile = __DIR__ . '/../lib/Application.php';
if (file_exists($baseFile)) {
require_once $baseFile;
}
Horde_Registry::appInit(<app>, array('authentication' => false, 'cli' => true));
$driver = $GLOBALS['injector']->getInstance('<app>_Factory_Driver')->create();
$processes = $driver->getProcessestoStart();
foreach($processes as $process) {
$pid = pcntl_fork();
if ($pid == -1) { // Error in forking
throw new <app>_Exception('Unable to fork.');
} elseif ($pid) { // Parent process
} else { // End process
start_process($process);
exit;
}
}
function start_process($process) {
$driver = $GLOBALS['injector']->getInstance('<app>_Factory_Driver')->create();
require_once 'AWSSDKforPHP/sdk.class.php';
$ec2 = new AmazonEC2(array('key' => $GLOBALS['conf']['aws']['key'], 'secret' => $GLOBALS['conf']['aws']['secretkey']));
$response = $ec2->create_key_pair($process['key_name']);
$driver->addClusterLog($process['cluster_id'], $response);
....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment