View source
<?php
function background_process_dispatcher_http($process) {
$process
->logDebug(__FUNCTION__);
list($url, $headers) = background_process_build_request('bgp-start/' . $process
->getPID(), $process
->getServiceHost(), array(
'query' => array(
'handle' => $process
->getHandle(),
),
));
$headers['Content-Type'] = 'application/x-www-form-urlencoded';
$data = 'token=' . $process
->getToken();
if ($process
->getPhase()) {
$data .= '&process=' . base64_encode(serialize($process));
$data .= '&module=' . base64_encode(drupal_get_path('module', 'background_process'));
$data .= '&DRUPAL_ROOT=' . base64_encode(DRUPAL_ROOT);
$url = url(drupal_get_path('module', 'background_process') . '/background_process.bootstrap.php', array(
'query' => array(
'handle' => $process
->getHandle(),
),
'absolute' => TRUE,
));
}
$options = array(
'method' => 'POST',
'data' => $data,
'headers' => $headers,
'blocking' => FALSE,
);
$result = background_process_http_request($url, $options);
$process->connection = $result->fp;
}
function background_process_dispatcher_http_title($service_host) {
return sprintf("http: %s - %s", $service_host['base_url'], $service_host['http_host']);
}
function background_process_dispatcher_http_options($service_host) {
global $base_url;
$options = array(
'base_url' => $base_url,
'http_host' => isset($service_host['http_host']) ? $service_host['http_host'] : parse_url($base_url, PHP_URL_HOST),
);
return $options;
}
function background_process_dispatcher_drush($process) {
$service_hosts = background_process_get_service_hosts();
$service_host = $service_hosts[$process
->getServiceHost()];
$cmd = !empty($service_host['drush_cmd']) ? $service_host['drush_cmd'] : variable_get('background_process_drush_cmd', BACKGROUND_PROCESS_DRUSH_CMD);
if (!empty($service_host['site_alias'])) {
$cmd .= ' @' . $service_host['site_alias'];
}
$logfile = '/dev/null';
$logfile = '/tmp/drupal-drush.log';
$realcmd = "{$cmd} bgp-execute " . escapeshellarg($process
->getPID()) . " >> " . escapeshellarg($logfile) . " 2>&1 &";
exec($realcmd);
$process->connection = TRUE;
}
function background_process_dispatcher_drush_title($service_host) {
return sprintf("drush: %s", $service_host['site_alias']);
}
function background_process_dispatcher_drush_options($service_host) {
global $base_url;
$options = array(
'drush_cmd' => !empty($service_host['drush_cmd']) ? $service_host['drush_cmd'] : variable_get('background_process_drush_cmd', BACKGROUND_PROCESS_DRUSH_CMD),
'site_alias' => !empty($service_host['site_alias']) ? $service_host['site_alias'] : '',
);
return $options;
}
function background_process_dispatcher_queue($process) {
$service_hosts = background_process_get_service_hosts();
$service_host = $service_hosts[$process
->getServiceHost()];
$queue = DrupalQueue::get($service_host['queue']);
$queue
->createItem($process
->getPID());
}
function background_process_dispatcher_queue_title($service_host) {
return sprintf("queue: %s", $service_host['queue']);
}
function background_process_dispatcher_queue_options($service_host) {
$options = array();
$options['queue'] = isset($service_host['queue']) ? $service_host['queue'] : 'background_process';
return $options;
}
function background_process_dispatcher_foreground($process) {
$process
->execute();
}
function background_process_dispatcher_foreground_title($service_host) {
return sprintf("foreground");
}