Skip to content
Snippets Groups Projects
Commit 9f6b3bd3 authored by Brett Bieber's avatar Brett Bieber
Browse files

Reduce dependency stack of rewrite map script to prevent hangs

This moves the logic for cache misses to a separate script,
rewrite_miss.php, which will process the rewrite and return
the correct route. The rewrite_miss.php script includes a
time limit to prevent hang-ups from occurring.
Closes #424
parent de49d1f3
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/php #!/usr/bin/php
<?php <?php
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/unl_bootstrap.inc';
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
$stdin = fopen('php://stdin', 'r'); $stdin = fopen('php://stdin', 'r');
$cache = new RewriteCache(); $cache = new RewriteCache();
...@@ -16,41 +11,21 @@ while ($line = fgets($stdin)) { ...@@ -16,41 +11,21 @@ while ($line = fgets($stdin)) {
// Check for this result in the cache // Check for this result in the cache
if (!($output = $cache->get($line))) { if (!($output = $cache->get($line))) {
// Parse the 3 fields. exec('/usr/bin/php ' . __DIR__ . '/rewrite_miss.php ' . escapeshellarg($line), $output, $return_var);
list($host, $uri, $path) = explode(';delim;', $line);
// Set default route
// Get the base path of the drupal install $route = 'NULL';
$base_path = substr($uri, 0, strlen($uri) - strlen($path));
if (!$return_var && isset($output[0])) {
// Set up some _SERVER variables as if this was a HTTP request. //Success! a route was found
$_SERVER['SCRIPT_NAME'] = $base_path . 'index.php'; $route = $output[0];
$_SERVER['SCRIPT_FILENAME'] = DRUPAL_ROOT . '/index.php';
$_SERVER['REQUEST_URI'] = $uri;
$_SERVER['HTTP_HOST'] = $host;
// Call the UNL bootstrap to fix conf_path and SCRIPT_NAME
unl_bootstrap();
$site_dir = conf_path();
$base_path = substr($_SERVER['SCRIPT_NAME'], 0, -9);
// Now we fix the drupal path.
$drupal_path = substr($uri, strlen($base_path));
// Finally, generate the path to the file we might be accessing
$file_path = $site_dir . '/files/' . $drupal_path;
// If that file exists, return the correct path to it, otherwise, return what we were given.
if (is_file($file_path)) {
$output = $file_path;
}
else {
$output = 'NULL';
} }
$cache->set($line, $output); $cache->set($line, $route);
} }
echo $output . PHP_EOL; echo $route . PHP_EOL;
} }
......
<?php
if (!isset($argv, $argv[1])) {
echo 'NULL';
exit(1);
}
$line = $argv[1];
set_time_limit(5);
define('DRUPAL_ROOT', __DIR__);
require_once DRUPAL_ROOT . '/includes/unl_bootstrap.inc';
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
// Parse the 3 fields.
list($host, $uri, $path) = explode(';delim;', $line);
// Get the base path of the drupal install
$base_path = substr($uri, 0, strlen($uri) - strlen($path));
// Set up some _SERVER variables as if this was a HTTP request.
$_SERVER['SCRIPT_NAME'] = $base_path . 'index.php';
$_SERVER['SCRIPT_FILENAME'] = DRUPAL_ROOT . '/index.php';
$_SERVER['REQUEST_URI'] = $uri;
$_SERVER['HTTP_HOST'] = $host;
// Call the UNL bootstrap to fix conf_path and SCRIPT_NAME
unl_bootstrap();
$site_dir = conf_path();
$base_path = substr($_SERVER['SCRIPT_NAME'], 0, -9);
// Now we fix the drupal path.
$drupal_path = substr($uri, strlen($base_path));
// Finally, generate the path to the file we might be accessing
$file_path = $site_dir . '/files/' . $drupal_path;
// If that file exists, return the correct path to it, otherwise, return what we were given.
if (is_file($file_path)) {
$output = $file_path;
}
else {
$output = 'NULL';
}
echo $output;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment