Commit cc4ea729 authored by mikeytown2's avatar mikeytown2

Issue #1994054 by mikeytown2: Use httprl_async_function_callback for...

Issue #1994054 by mikeytown2: Use httprl_async_function_callback for non-blocking test instead of admin/httprl-test.
parent 4b9f9617
......@@ -64,13 +64,13 @@ function httprl_requirements($phase) {
if ($phase == 'runtime') {
// Check that the menu router item is working. If it is not working, the
// rest of the tests below will be pointless.
$item = menu_get_item('admin/httprl-test');
$item = menu_get_item('httprl_async_function_callback');
if (empty($item['page_callback']) || strpos($item['page_callback'], 'httprl') === FALSE) {
$requirements['httprl_callback'] = array(
'title' => $t('HTTPRL - Menu Callback'),
'severity' => REQUIREMENT_WARNING,
'value' => $t('Flush your caches'),
'description' => $t('You need to flush your menu cache. The test callback for httprl is not there.'),
'description' => $t('You need to flush your menu cache. The background callback for httprl is not there.'),
);
return $requirements;
}
......@@ -164,43 +164,84 @@ function httprl_requirements($phase) {
* (Optional) HTTPRL blocking mode.
*/
function httprl_install_http_test($mode, $blocking = FALSE) {
global $base_root, $base_path, $conf, $_httprl;
$url_path = 'admin/httprl-test';
$id = 'httprl_' . md5(mt_rand() . time());
// Build URL to point to admin/httprl-test on this server.
$url = httprl_build_url_self($url_path . '?key=' . md5(drupal_get_private_key()) . '&id=' . $id, TRUE);
// Set the headers to point to this hostname.
$headers = array(
'Host' => $_SERVER['HTTP_HOST'],
);
global $conf, $_httprl;
$id = 'httprl_' . hash('sha512', mt_rand() . microtime(TRUE));
// Add in the headers and set the blocking mode.
$options = array(
'headers' => $headers,
'blocking' => $blocking,
'timeout' => 6.0,
$args = array(
array(
'function' => 'httprl_lock_release',
'return' => '',
// Setup options array.
'options' => array(
'blocking' => $blocking,
'timeout' => 6,
'max_redirects' => 3,
),
),
$id,
);
$args_copy = $args;
// Start the timer & get a lock.
timer_start($id);
lock_acquire($id, 6);
// Choose how to issue the HTTP request.
if ($mode == 1) {
if ($mode == 2) {
// Queue up the request.
$url = httprl_queue_background_callback($args);
$url = array_keys($url);
$url = array_pop($url);
// Execute request.
httprl_send_request();
}
else {
// Get options.
$callback_options = array_shift($args);
// Build URL to point to httprl_async_function_callback on this server.
$url = httprl_build_url_self('httprl_async_function_callback?count=0', TRUE);
// Set the headers to point to this hostname.
$headers = array(
'Host' => $_SERVER['HTTP_HOST'],
);
// Create lock name for this run.
$available = FALSE;
$lock_counter = 0;
while (!$available && $lock_counter < 20) {
$name = 'httprl_' . hash('sha512', mt_rand() . microtime(TRUE));
$available = lock_may_be_available($name);
$lock_counter++;
}
$callback_options['options']['lock_name'] = $name;
lock_acquire($name, $callback_options['options']['timeout']);
// Create data array and options for request.
$options = array(
'data' => array(
'master_key' => hash('sha512', httprl_drupal_get_private_key()),
'temp_key' => $name,
'mode' => TRUE,
'php_timeout' => $callback_options['options']['timeout'],
'function' => $callback_options['function'],
'args' => serialize($args),
),
'method' => 'POST',
'headers' => $headers,
'timeout' => $callback_options['options']['timeout'],
'max_redirects' => $callback_options['options']['max_redirects'],
);
httprl_handle_data($options);
// Execute the request using core.
if (defined('VERSION') && substr(VERSION, 0, 1) >= 7) {
drupal_http_request($url, $options);
}
else {
drupal_http_request($url, $headers);
drupal_http_request($url, $options['headers'], $options['method'], $options['data'], $options['max_redirects'], $options['timeout']);
}
}
elseif ($mode == 2) {
// Execute the request using httprl.
httprl_request($url, $options);
$requests = httprl_send_request();
}
// Wait for the lock and stop the timer.
lock_wait($id);
......@@ -210,6 +251,7 @@ function httprl_install_http_test($mode, $blocking = FALSE) {
$time['mode'] = $mode;
$time['blocking'] = $blocking;
$time['url'] = $url;
$time['args'] = $args_copy;
$_httprl['install']['debug'][] = $time;
// See if the request came back in under 5 seconds, or if it timed out.
......
......@@ -133,16 +133,6 @@ define('HTTPRL_PR_MAX_STRING_LENGTH', 262144);
function httprl_menu() {
$items = array();
// Non blocking test URL.
$items['admin/httprl-test'] = array(
'title' => 'HTTPRL',
'page callback' => 'httprl_nonblockingtest_page',
'access callback' => TRUE,
'description' => 'Test URL to make sure non blocking requests work.',
'type' => MENU_CALLBACK,
'file' => 'httprl.nonblocktest.inc',
);
// Admin page.
if (defined('VERSION') && substr(VERSION, 0, 1) >= 7) {
$config_url = 'admin/config/development/httprl';
......
<?php
/**
* @file
* Functions used to test loopback connections.
*/
/**
* Menu Callback; Release a lock if the right conditions are met.
*/
function httprl_nonblockingtest_page() {
// exit if
// The id is not set.
// The key is not set.
// The id does not start with httprl_.
// The key does not match the md5 of drupal_get_private_key().
if ( empty($_GET['id'])
|| empty($_GET['key'])
|| strpos($_GET['id'], 'httprl_') !== 0
|| $_GET['key'] != md5(httprl_drupal_get_private_key())
) {
httprl_fast403();
}
// Release the lock, echo out that the lock was cleared and exit.
httprl_lock_release($_GET['id']);
echo t('lock @id cleared', array('@id' => $_GET['id']));
// Exit Script.
httprl_call_exit();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment