Commit 6e2d07b9 authored by mikeytown2's avatar mikeytown2

Issue #155314 by mikeytown2: Add in examples to readme file.

parent 6c396932
......@@ -338,3 +338,198 @@ the same options.
echo httprl_pr($request);
?>
Get 2 results from 2 different queries at the hook_boot bootstrap level in D6.
<?php
// Run 2 queries and get the result.
$x = db_result(db_query_range("SELECT filename FROM {system} ORDER BY filename ASC", 0, 1));
$y = db_result(db_query_range("SELECT filename FROM {system} ORDER BY filename DESC", 0, 1));
echo $x . "<br \>\n" . $y . "<br \>\n";
unset($x, $y);
// Run above 2 queries and get the result via a background callback.
$args = array(
// First query.
array(
'type' => 'function',
'call' => 'db_query_range',
'args' => array('SELECT filename FROM {system} ORDER BY filename ASC', 0, 1),
),
array(
'type' => 'function',
'call' => 'db_result',
'args' => array('last' => NULL),
'return' => &$x,
),
// Second Query.
array(
'type' => 'function',
'call' => 'db_query',
'args' => array('SELECT filename FROM {system} ORDER BY filename DESC', 0, 1),
),
array(
'type' => 'function',
'call' => 'db_result',
'args' => array('last' => NULL),
'return' => &$y,
),
);
$callback_options = array(array('return' => ''), &$args);
// Queue up the request.
httprl_queue_background_callback($callback_options);
// Execute request.
httprl_send_request();
// Echo what was returned.
echo httprl_pr($x, $y);
?>
Get 2 results from 2 different queries at the hook_boot bootstrap level in D7.
<?php
$x = db_select('system', 's')
->fields('s', array('filename'))
->orderBy('filename', 'ASC')
->range(0, 1)
->execute()
->fetchField();
$y = db_select('system', 's')
->fields('s', array('filename'))
->orderBy('filename', 'DESC')
->range(0, 1)
->execute()
->fetchField();
echo $x . "<br \>\n" . $y . "<br \>\n";
unset($x, $y);
// Run above 2 queries and get the result via a background callback.
$args = array(
// First query.
array(
'type' => 'function',
'call' => 'db_select',
'args' => array('system', 's',),
),
array(
'type' => 'method',
'call' => 'fields',
'args' => array('s', array('filename')),
),
array(
'type' => 'method',
'call' => 'orderBy',
'args' => array('filename', 'ASC'),
),
array(
'type' => 'method',
'call' => 'range',
'args' => array(0, 1),
),
array(
'type' => 'method',
'call' => 'execute',
'args' => array(),
),
array(
'type' => 'method',
'call' => 'fetchField',
'args' => array(),
'return' => &$x,
),
// Second Query.
array(
'type' => 'function',
'call' => 'db_select',
'args' => array('system', 's',),
),
array(
'type' => 'method',
'call' => 'fields',
'args' => array('s', array('filename')),
),
array(
'type' => 'method',
'call' => 'orderBy',
'args' => array('filename', 'DESC'),
),
array(
'type' => 'method',
'call' => 'range',
'args' => array(0, 1),
),
array(
'type' => 'method',
'call' => 'execute',
'args' => array(),
),
array(
'type' => 'method',
'call' => 'fetchField',
'args' => array(),
'return' => &$y,
),
);
$callback_options = array(array('return' => ''), &$args);
// Queue up the request.
httprl_queue_background_callback($callback_options);
// Execute request.
httprl_send_request();
// Echo what was returned.
echo httprl_pr($x, $y);
?>
Run a cache clear at the DRUPAL_BOOTSTRAP_FULL level as the current user in a
non blocking background request.
<?php
// Normal way to do this.
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
module_load_include('inc', 'system', 'system.admin');
system_clear_cache_submit();
// How to do it in a non blocking background request.
$args = array(
array(
'type' => 'function',
'call' => 'drupal_bootstrap',
'args' => array(DRUPAL_BOOTSTRAP_FULL),
),
array(
'type' => 'function',
'call' => 'module_load_include',
'args' => array('inc', 'system', 'system.admin'),
),
array(
'type' => 'function',
'call' => 'system_clear_cache_submit',
'args' => array('', ''),
),
array(
'type' => 'function',
'call' => 'watchdog',
'args' => array('httprl-test', 'background cache clear done', array(), WATCHDOG_DEBUG),
),
);
// Pass the current session to the sub request.
if (!empty($_COOKIE[session_name()])) {
$options = array('headers' => array('Cookie' => session_name() . '=' . $_COOKIE[session_name()] . ';'));
}
else {
$options = array();
}
$callback_options = array(array('options' => $options), &$args);
// Queue up the request.
httprl_queue_background_callback($callback_options);
// Execute request.
httprl_send_request();
?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment