Alternative to drupal_bootstrap when we want to access Drupal data from other application?
Hello, I want to use some Drupal7 functions such as node_load, taxonomy_term_load in my custom written PHP applications. I managed to use them by running a full drupal bootstrap, function is okay, i.e. drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); $node = node_load(123); However, when profiling the code using Xdebug, I found drupal_bootstrap is just too heavy, i.e. used 80% of my application CPU time even I am doing simple query such as node_load. Of course, I can direct query the Drupal DB but I don't want to reinvent the wheel, but now seems it is too much overhead. Any suggestion when outside application want to access Drupal data, for the above basic query (read only)? Thanks.
Hi, You could just bootstrap the database, but not all the modules will be loaded, and you may not get back the same results, as you would in drupal. What the other problem could be that it is doing a lot in hook_init() which you could skip by defining MAINTENANCE_MODE as update. see http://api.drupalecommerce.org/api/drupal/drupal--includes--common.inc/funct... Gordon. On 13/02/2011, at 2:06 PM, Ryan Chan wrote:
Hello,
I want to use some Drupal7 functions such as node_load, taxonomy_term_load in my custom written PHP applications.
I managed to use them by running a full drupal bootstrap, function is okay,
i.e.
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); $node = node_load(123);
However, when profiling the code using Xdebug, I found drupal_bootstrap is just too heavy, i.e. used 80% of my application CPU time even I am doing simple query such as node_load.
Of course, I can direct query the Drupal DB but I don't want to reinvent the wheel, but now seems it is too much overhead.
Any suggestion when outside application want to access Drupal data, for the above basic query (read only)?
Thanks.
Alternatively, consider using a service (xmlrpc, rest) or pulling the data off a view using xml or similar. If you cache the data at the Drupal end the relative performance hit will be minimal. chris On 13/02/2011, at 2:10 PM, Gordon Heydon wrote:
Hi,
You could just bootstrap the database, but not all the modules will be loaded, and you may not get back the same results, as you would in drupal.
What the other problem could be that it is doing a lot in hook_init() which you could skip by defining MAINTENANCE_MODE as update.
see http://api.drupalecommerce.org/api/drupal/drupal--includes--common.inc/funct...
Gordon.
On 13/02/2011, at 2:06 PM, Ryan Chan wrote:
Hello,
I want to use some Drupal7 functions such as node_load, taxonomy_term_load in my custom written PHP applications.
I managed to use them by running a full drupal bootstrap, function is okay,
i.e.
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); $node = node_load(123);
However, when profiling the code using Xdebug, I found drupal_bootstrap is just too heavy, i.e. used 80% of my application CPU time even I am doing simple query such as node_load.
Of course, I can direct query the Drupal DB but I don't want to reinvent the wheel, but now seems it is too much overhead.
Any suggestion when outside application want to access Drupal data, for the above basic query (read only)?
Thanks.
On Sun, Feb 13, 2011 at 11:10 AM, Gordon Heydon <gordon@heydon.com.au> wrote:
Hi,
You could just bootstrap the database, but not all the modules will be loaded, and you may not get back the same results, as you would in drupal.
What the other problem could be that it is doing a lot in hook_init() which you could skip by defining MAINTENANCE_MODE as update.
see http://api.drupalecommerce.org/api/drupal/drupal--includes--common.inc/funct...
Gordon.
If I just bootstrap the database, error will be shown:
Call to undefined function node_load()
Also, the MAINTENANCE_MODE tricks seem help, will do more analysis later on. Thanks.
If you start skipping bootstrap phases then modules that inject data via hook_node_load() or hook_entity_load() will not get run. Dave Reid dave@davereid.net On Sat, Feb 12, 2011 at 9:06 PM, Ryan Chan <ryanchan404@gmail.com> wrote:
Hello,
I want to use some Drupal7 functions such as node_load, taxonomy_term_load in my custom written PHP applications.
I managed to use them by running a full drupal bootstrap, function is okay,
i.e.
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); $node = node_load(123);
However, when profiling the code using Xdebug, I found drupal_bootstrap is just too heavy, i.e. used 80% of my application CPU time even I am doing simple query such as node_load.
Of course, I can direct query the Drupal DB but I don't want to reinvent the wheel, but now seems it is too much overhead.
Any suggestion when outside application want to access Drupal data, for the above basic query (read only)?
Thanks.
There is no way to skip that. On Mon, Feb 14, 2011 at 2:41 AM, Dave Reid <dave@davereid.net> wrote:
If you start skipping bootstrap phases then modules that inject data via hook_node_load() or hook_entity_load() will not get run. Dave Reid dave@davereid.net
On Sat, Feb 12, 2011 at 9:06 PM, Ryan Chan <ryanchan404@gmail.com> wrote:
Hello,
I want to use some Drupal7 functions such as node_load, taxonomy_term_load in my custom written PHP applications.
I managed to use them by running a full drupal bootstrap, function is okay,
i.e.
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); $node = node_load(123);
However, when profiling the code using Xdebug, I found drupal_bootstrap is just too heavy, i.e. used 80% of my application CPU time even I am doing simple query such as node_load.
Of course, I can direct query the Drupal DB but I don't want to reinvent the wheel, but now seems it is too much overhead.
Any suggestion when outside application want to access Drupal data, for the above basic query (read only)?
Thanks.
-- A decathlon Drupal developer & programmer http://blog.eood.cn/
participants (5)
-
Bruce Dou -
Chris Skene -
Dave Reid -
Gordon Heydon -
Ryan Chan