[development] Any reason why having a javascript timer fire every 2.5 second for an ajax request to my own callback(listed below) that all it does is return the contents of 2 _session variables would take up so much resources?
Greg Knaddison
greg at growingventuresolutions.com
Sun Feb 6 17:21:15 UTC 2011
Drupal's bootstrap takes something like 50% of the total page
processing time on a typical page. You are still paying for that
overhead even though you don't need it.
See http://api.drupal.org/api/drupal/includes--bootstrap.inc/function/drupal_bootstrap/6
and look at something like the chatroom module's lightweight bootstrap
code:
http://drupalcode.org/viewvc/drupal/contributions/modules/chatroom/chatroomread.php?revision=1.29.4.19&view=markup
In particular:
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);
// Choose the minimum bootstrap level necessary for your module.
// Put your code here.
// See performance skyrocket.
// Rejoice.
Regards,
Greg
On Sun, Feb 6, 2011 at 10:15 AM, John Mitchell <mitchelljj98 at gmail.com> wrote:
> Any reason why having a javascript timer fire every 2.5 second for an ajax
> request to my own callback(listed below) that all it does is return the
> contents of 2 _session variables would take up so much resources?
>
> John
>
> function refreshcarttimer() {
> print($_SESSION['num_items'] . ',' . $_SESSION['uc_price']);
> return;
> }
>
> /**
> * Implementation of hook_menu().
> */
>
> function product_type_menu() {
> $items = array();
>
> $items['cart/refreshcarttimer'] = array(
> 'title' => 'Refresh Shopping Cart',
> 'description' => 'Refresh Shopping Cart',
> 'page callback' => 'refreshcarttimer',
> 'access callback' => TRUE,
> 'type' => MENU_CALLBACK,
> );
> return $items;
> }
>
> On Sun, Feb 6, 2011 at 2:10 AM, John Mitchell <mitchelljj98 at gmail.com>
> wrote:
>>
>> I have a javascript timer set to fire every 2.5 seconds so that I can set
>> the current values for the items and total for the shopping cart summary. I
>> would like to be able to get these values from client side cookies or
>> javascript global variables so that I don't have to make an ajax call to the
>> server but I have found that the DOM elements are not accessible within the
>> javascript function unless I run an ajax request to a page (listed below)
>> and after it returns then the DOM elements are accessible (i.e.
>> $(".num-items").html(numItems);) and now I can update them. Having these
>> ajax requests run every 2.5 seconds for every client will not scale.
>>
>> How can I make Drupal DOM elements accessible within a javascript function
>> without having to do an ajax request to a page?
>>
>> Thanks,
>>
>> John
>>
>> setInterval('updateShoppingCartInfo()', 2500);
>>
>> function updateShoppingCartInfo(){
>> var xmlHttpReq = new XMLHttpRequest();
>> var url = 'https://' + document.domain + '/cart/refreshcarttimer';
>> xmlHttpReq.open('post', url, true);
>> xmlHttpReq.onreadystatechange = function() {
>> if (xmlHttpReq.readyState != 4) {
>> return;
>> }
>> else {
>> var responseText = xmlHttpReq.responseText;
>> var numItems =
>> responseText.substr(0,responseText.indexOf(","));
>> var ucPrice =
>> responseText.substr(responseText.indexOf(",")+1);
>> $(".num-items").html(numItems);
>> $(".uc-price").html(ucPrice);
>> }
>> }
>> xmlHttpReq.send(null);
>> }
>>
>>
>> --
>> John J. Mitchell
>
>
>
> --
> John J. Mitchell
>
--
Greg Knaddison | 720-310-5623 | http://growingventuresolutions.com
http://masteringdrupal.com - Videos and Tutorials
More information about the development
mailing list