system_check_http_request

Definition

system_check_http_request()
modules/system/system.module, line 1875

Description

Checks whether the server is capable of issuing HTTP requests.

The function sets the drupal_http_request_fail system variable to TRUE if drupal_http_request() does not work and then the system status report page will contain an error.

Return value

Whether the admin/reports/request-test page can be requested via HTTP and contains the same output as if called via the menu system.

Code

<?php
function system_check_http_request() {
  // Check whether we can do any request at all. First get the results for
  // a very simple page which has access TRUE set via the menu system. Then,
  // try to drupal_http_request() the same page and compare.
  ob_start();
  $path = 'admin/reports/request-test';
  menu_execute_active_handler($path);
  $nothing = ob_get_contents();
  ob_end_clean();
  $result = drupal_http_request(url($path, array('absolute' => TRUE)));
  $works = isset($result->data) && $result->data == $nothing;
  variable_set('drupal_http_request_fails', !$works);
  return $works;
}
?>
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.