Hi,

I'm somewhat new to Drupal but have developed a few modules for a private website (it's a Search & Rescue organization with some nifty custom software that I've been developing using Drupal).

Some of my most recent modules use AJAX: javascript is on the client computer and sends JSON-formatted requests (using jquery), where I have a normal Drupal menu-item in my module that receives and processes the request (Drupal DB access/update), and then replies to the client.

For example, this is my Drupal "menu" item that receives the message from the client and invokes "roster_mco_processClient":

   $items[] = array('path' => 'roster/mco/processClient',
                    'title' => t('Roster MCO Client'),
                    'callback' => 'roster_mco_processClient',
                    'access' => user_access('access roster'),
                    'weight' => $weight++,
                    'type' => MENU_CALLBACK);

I've been struggling with 900-1000ms POST / RESPONSE times and finally figured out what everyone probably knows except me: the DRUPAL_BOOTSTRAP_FULL is quite intensive and time-consuming for (in my case) a simple AJAX application that just needs access to various Drupal databases.

Tonight, instead of using the Drupal "index.php", I created my own .php file with the following contents (I placed the new file in the root directory alongside Drupal's "index.php"):

<? php
   include_once 'includes/bootstrap.inc';
   include_once 'includes/common.inc';
   include_once 'sites/all/modules/roster/roster.module';

   drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);

   // Invoke my module directly to process & respond to the AJAX request:
   roster_mco_processClient();

   exit();

And I changed my javascript client software to request my .php file above when it sends an AJAX query, instead of the old query which would cause the Drupal "index.php" to execute.

Instead of 900-1000ms POST/RESPONSE times, I'm now seeing between 94ms-120ms POST/RESPONSE times! I can't believe how much faster my application is executing with the simple change above.

Fearing that this must be too good to be true, am I opening a bag of worms by taking this approach regarding security or other potential threats? Is Drupal 6 better with respect to AJAX performance? Do other people get better response times without resorting to my approach above?

Regards,

J

Comments

tjholowaychuk’s picture

Great question! Most of our response times are very similar to yours, which is certainly to long for what could be a 'simple' request.

Unfortunately most of the responses in alot of these modules will no doubt need functions such as user_access();, node_load(); etc. hmm...
____________________________________________________
Tj Holowaychuk

Vision Media
350designs
Design Inspiration

catch’s picture

This forum is deprecated - you should probably submit this as an issue to Drupal 7 at http://drupal.org/node/add/project-issue/drupal instead, after checking there's not already one there.

jmmec’s picture

Thanks for the responses -- I posted over in the "Javascript" Drupal group and got a response confirming that my approach is adequate for my purposes:

http://groups.drupal.org/node/9743

It looks like something better is coming in Drupal 7 to better customize what needs to be loaded / etc. That would be nice.

Regards