2

I have a production site with page caching enabled (this is not negotiable). One very popular feature requires dynamic content to be queried from an external socket and displayed; this content is required to be fresh at all times and cannot be cached. Current implementation has a vanilla, non-Drupal .php script polling the socket, whose output is either pulled into the page via javascript, or put in an iframe if no js. The vanilla .php is not cached by Drupal, but the rest of the page (menus etc.) is cached. It's fast.

Due to new requirements, the hard-coded config in the vanilla .php must instead be configurable through the Drupal UI. I have a working admin implementation, and have brought the socket-polling code inside the Drupal module. It's slow.

Putting the dynamic content in a block with DRUPAL_NO_CACHE doesn't help, because the whole page is being cached, ignoring block-level settings. Excluding the whole page (including menus etc.) from the cache will not meet performance requirements. I don't think I can use the javascript/iframe trick again, unless there's a way to get Drupal to render a minimal uncached page without building any of the rest of the site. Using 'print $my_html;' in the hook_block_view rather than 'return $my_html;' renders a page with just the dynamic content, but it performs slowly enough that I think Drupal is doing a lot of unnecessary work. Is there a better way of rendering a very-minimal page while still having access to e.g. variable_get()?

Is there a better way to approach this? Being able to set block caching independently of its parent page caching would be nice...

(Using local dev servers, a fully uncached page takes about 1000ms to render. The 'minimal print-don't-return' page takes about 400ms. The actual module code for getting the dynamic content takes 6ms of this. A fully cached page renders in 20ms.)

0

"unless there's a way to get Drupal to render a minimal uncached page without building any of the rest of the site"

There's the clue - yes, there is. This is what AJAX callbacks do, after all. In your menu callback you print the desired output instead of returning it, and return NULL. IIRC, the result won't be subject to page caching either, but if it is, you can use the cache exclude module to ensure it is not cached.

  • Caveat: the minimal page will still do a full bootstrap, so if that's too heavy you may need to write some custom PHP which does a partial bootstrap only. – Alfred Armstrong Apr 4 '13 at 14:04
  • 1
    Thanks - indeed I've tried printing rather than returning, but the unnecessary bootstrap it does anyway is unacceptably slow. I'd been struggling to find a useful string to google, so thanks for 'partial bootstrap'! Something like this looks promising: interworks.com/blogs/jkhalaj/2012/05/01/how-bootstrap-drupal – Liche Apr 4 '13 at 14:15
  • I have a working implementation using drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES); in a nearly-standalone .php script, and it is performing acceptably. Thank you for your help. – Liche Apr 4 '13 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.