diff --git a/httprl.install b/httprl.install index 2c8ca58..0189757 100644 --- a/httprl.install +++ b/httprl.install @@ -47,7 +47,7 @@ function httprl_requirements($phase) { // Check each function to make sure it exists. foreach ($function_list as $function_name) { if (!function_exists($function_name)) { - $requirements['httprl-function-' . $function_name] = array( + $requirements['httprl_function_' . $function_name] = array( 'title' => $t('HTTPRL'), 'value' => $phase == 'install' ? FALSE : $function_name, 'severity' => REQUIREMENT_ERROR, @@ -58,15 +58,72 @@ function httprl_requirements($phase) { ); } } + } + if ($phase == 'runtime') { + $url_path = 'admin/httprl-test'; + // Check that the menu router handler is working. If it's not working the rest + // of the tests are pointless. + $item = menu_get_item($url_path); + if (empty($item['page_callback']) || strpos($item['page_callback'], 'httprl') === FALSE) { + $item = str_replace(' ', '    ', nl2br(htmlentities(print_r($item, TRUE)))); + $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.'), + ); + return $requirements; + } + + // Test the non blocking url + global $base_root, $base_path; + // Build URL to point to admin/httprl-test on this server. + $ip = empty($_SERVER['SERVER_ADDR']) ? '127.0.0.1' : $_SERVER['SERVER_ADDR']; + $id = 'httprl_' . md5(mt_rand() . time()); + $url_ip = 'http://' . $ip . $base_path . $url_path . '?key=' . md5(drupal_get_private_key()) . '&id=' . $id; + $url_host = $base_root . $base_path . $url_path . '?key=' . md5(drupal_get_private_key()) . '&id=' . $id; + // Set the headers to point to this hostname. + $headers = array( + 'Host' => $_SERVER['HTTP_HOST'], + ); + + // Add in the headers and set the blocking mode. + $options = array( + 'headers' => $headers, + 'blocking' => FALSE, + 'timeout' => 6.0, + ); + + // Start the timer & Get a lock. + timer_start($id); + lock_acquire($id, 6); + + // Queue up the requests & execute them. + httprl_request($url_ip, $options); + httprl_request($url_host, $options); + $requests = httprl_send_request(); - if (empty($requirements)) { - $requirements['httprl'] = array( - 'title' => $t('HTTPRL'), - 'severity' => REQUIREMENT_OK, - 'value' => $phase == 'install' ? TRUE : $t('All the required functions are enabled.'), + // Wait for the lock and stop the timer. + lock_wait($id); + $time = timer_stop($id); + if (($time['time'] / 1000) > 5) { + // Lock timed out and was not reset by the URL ping. + $requirements['httprl_nonblocking'] = array( + 'title' => $t('HTTPRL - Non Blocking'), + 'severity' => REQUIREMENT_WARNING, + 'value' => $t('This server does not handle hanging connections.'), + 'description' => $t('Using non blocking mode on this server my not work correctly. More info: !info', array('!info' => str_replace(' ', '    ', nl2br(htmlentities(print_r(array($time, $requests), TRUE)))))), ); } } + if (empty($requirements)) { + $requirements['httprl'] = array( + 'title' => $t('HTTPRL'), + 'severity' => REQUIREMENT_OK, + 'value' => $phase == 'install' ? TRUE : $t('All the required functions are enabled and non blocking requests are working.'), + ); + } + return $requirements; } diff --git a/httprl.module b/httprl.module index b3b2298..04b38e1 100755 --- a/httprl.module +++ b/httprl.module @@ -6,9 +6,29 @@ * */ +/** + * Error code indicating that the request made by httprl_send_request() failed + * to write to the open stream. + */ define('HTTP_REQUEST_FWRITE_FAIL', -2); /** + * Implement hook_menu(). + */ +function httprl_menu() { + $items = array(); + $items['admin/httprl-test'] = array( + 'title' => 'HTTPRL', + 'page callback' => 'httprl_nonblockingtest_page', + 'access callback' => TRUE, + 'description' => 'Ajax callback for view loading.', + 'type' => MENU_CALLBACK, + 'file' => 'httprl.nonblocktest.inc', + ); + return $items; +} + +/** * Perform an HTTP request * * @see drupal_http_request() diff --git a/httprl.nonblocktest.inc b/httprl.nonblocktest.inc new file mode 100644 index 0000000..a97f150 --- /dev/null +++ b/httprl.nonblocktest.inc @@ -0,0 +1,24 @@ + $_GET['id'])); + exit; +}