Hi,

I have a portion of a site which uses external data (legacy application). I use drupal_bootstrap to load drupal and add the headers and other regions around the legacy content. Drupal regions work fine and are being loaded as they should.

I should be able to use boost on these pages right? However, I could not make it work for the Drupal 6 version of boost - ( in Drupal 5, I was able to make it work )

In Drupal 5 - I was able to make it work by using the following command when user is anonymous:

...
if (user is anonymous) {
ob_start("_boost_ob_handler");
}
...

However in Drupal 6 - I see that the implementation is different already and tried using the following:

... 
if (user is anonymous) {
register_shutdown_function('_boost_ob_handler');
ob_start();
}
...

I have also added the following in the apache rewrite directives:

...
  # NORMAL
  RewriteCond %{DOCUMENT_ROOT}/cache/normal/%{SERVER_NAME}%{REQUEST_URI}_%{QUERY_STRING}\.html -s
  RewriteRule .* cache/normal/%{SERVER_NAME}%{REQUEST_URI}_%{QUERY_STRING}\.html [L,T=text/html]
  RewriteCond %{DOCUMENT_ROOT}/cache/normal/%{SERVER_NAME}%{REQUEST_URI}_%{QUERY_STRING}\.xml -s
  RewriteRule .* cache/normal/%{SERVER_NAME}%{REQUEST_URI}_%{QUERY_STRING}\.xml [L,T=text/xml]

  # LEGACY PAGES BOOST
  RewriteCond %{DOCUMENT_ROOT}/legacy_directory/cache/normal/%{SERVER_NAME}%{REQUEST_URI}_%{QUERY_STRING}\.html -s
  RewriteRule .* legacy_directory/cache/normal/%{SERVER_NAME}%{REQUEST_URI}_%{QUERY_STRING}\.html [L,T=text/html]
  
  
  ### BOOST END ###
...

I see some html files being generated under the "legacy_directory/cache" directory so it seems that boost is generating the static files as it should - however whenever I visit the pages as an anonymous user I don't see the line at the end of the source file that indicates that the page was generated by boost.

Does anyone know how can this be done? What am I missing?

Thanks for any information on this.

Comments

h3000’s picture

Hi,

I looked deeper into the boost module code and saw some code about the boost_pre_process_function.

...
function boost_cache_set($path, $data, $extension = BOOST_FILE_EXTENSION){
...
  // Invoke hook_boost_preprocess($path, $data, $extension)
  foreach (module_implements('boost_preprocess') as $module) {
    if (($result = module_invoke($module, 'boost_preprocess', $path, $data, $extension)) != NULL) {
      $data = $result;
    }
  }
...

Is this a function that I can use for my problem?

Does anyone know of any documentation on how this can be used in my situation?

Thanks

mikeytown2’s picture

  // We only generate cached pages for anonymous visitors.
  if (empty($user->uid)) {
    $GLOBALS['_boost_cache_this'] = TRUE;
    register_shutdown_function('_boost_ob_handler');
    ob_start();
  }

Set boost verbose to 9 and check out the watchdog for info

h3000’s picture

Hi mikeytown2,

thanks for the response.

ok - I tried setting the $GLOBALS['_boost_cache_this'] variable to true and set the boost verbose to 9.

What should I be looking for?

mikeytown2’s picture

Generally with the verbose level set at 9, something should be written to the watchdog once inside the _boost_ob_handler() function... actually after looking at this, you might have to set the $GLOBALS['_boost_router_item'] array. I use this to keep track of the complex relationships between the pages that Drupal generates.

Example structure:
['_boost_router_item']['page_callback'] - Taxonomy
['_boost_router_item']['page_type'] - Vocabulary
['_boost_router_item']['page_id'] - Term

So whatever your generating make sure to make the page_id unique if possible to each unique page.

mikeytown2’s picture

Status: Active » Needs review
h3000’s picture

ok

I see some entries related to the legacy portion of the site.

This is the output in watchdog:

Debug: _boost_ob_handler() 
HTTP Info: 200 - text/html 
Path: cache/normal/www.my_site.com/_catid=63.html 
Content Container: 
Content Type: Legacy 
ID: legacy_index_63
Cache This: TRUE.

this is how boost is being called:

...
if (anonymous) {
	$GLOBALS['_boost_cache_this'] = TRUE;
	$GLOBALS['_boost_router_item']['page_callback'] = "";
	$GLOBALS['_boost_router_item']['page_type'] = "Legacy";

	if (isset($_REQUEST["catid"])) {
		$GLOBALS['_boost_router_item']['page_id'] = "legacy_index" . "_" . $_REQUEST["catid"]; //to make id unique for each category
	} else {
		$GLOBALS['_boost_router_item']['page_id'] = "legacy_index";
	}

	register_shutdown_function('_boost_ob_handler');
	ob_start();
}
...

I also checked the cache directory under the legacy folder and I see a file cache/normal/www.my_site.com/_catid=63.html - so the file was generated properly. Is it a problem with the htaccess redirect rules?

mikeytown2’s picture

Underscores could be screwing it up (my_site.com)... I use that as a replacement for the ? character since using ? in a filename isn't smart. You can change the replacement character; just be sure to grab the new rules from the boost-rules admin page. Also I recommend setting the callback, leaving it blank is not recommended.

Is the url for that page
www.my_site.com/?catid=63.html

As for why the page is not being served by apache... does Boost work for pages that come from Drupal?

h3000’s picture

the url for the legacy portion of the site is:
http://www.shenzhenparty.com/classifieds

for that example, the url is:
http://www.shenzhenparty.com/classifieds/index.php?catid=3

the generated cache file is in
http://www.shenzhenparty.com/classifieds/cache/normal/www.shenzhenparty....

boost is working for the pages that come from drupal - which is at http://www.shenzhenparty.com

what should the value of the callback be?

mikeytown2’s picture

set callback to something like 'old' it doesn't really matter; as long as its not blank.

OK I think I figured it out. The classifieds directory is not getting picked up.
2 more variables to set
$GLOBALS['_boost_path']
$GLOBALS['_boost_query']

  //set variables
  $GLOBALS['_boost_path'] = $_REQUEST['q'];
  // Make the proper filename for our query
  $GLOBALS['_boost_query'] = BOOST_CHAR;
  $query = array();
  foreach ($_GET as $key => $val) {
    if ($key != 'q' && $key != 'destination') {
      $query[$key] = $val;
    }
  }
  $GLOBALS['_boost_query'] .= str_replace('&', '&', urldecode(http_build_query($query)));

So in this case www.shenzhenparty.com/classifieds/index.php?catid=3 do this:

$GLOBALS['_boost_path'] = 'classifieds/index.php';
$GLOBALS['_boost_query'] = '_catid=3';
h3000’s picture

After adding the two lines, this is what happened:

- a new directory under the classifieds cache directory was created named "classifieds"
- there were files inside this directory which corresponds to a certain page and arguments
- however, the page that was served was not the boosted page

- I tried copying the files into the main cache directory and when I checked the page, I got the boosted page
- it was now working but the cache could not be refreshed because it was looking for the boosted files in the main cache directory
- so the cached files are being created in the legacy directory but the file that was being served was from the main cache directory

bgm’s picture

Issue summary: View changes
Status: Needs review » Closed (cannot reproduce)

Closing old issue with no activity in a long time.