Commit 7f921776 authored by mikeytown2's avatar mikeytown2

Issue #1889006 by mikeytown2: Add in a save file example to the readme and...

Issue #1889006 by mikeytown2: Add in a save file example to the readme and update readme due to new changes in the API.
parent 2de28246
...@@ -27,7 +27,8 @@ limits, chunk size, and max redirects to follow. Can handle data with ...@@ -27,7 +27,8 @@ limits, chunk size, and max redirects to follow. Can handle data with
content-encoding and transfer-encoding headers set. Correctly follows content-encoding and transfer-encoding headers set. Correctly follows
redirects. Option to forward the referrer when a redirect is found. Cookie redirects. Option to forward the referrer when a redirect is found. Cookie
extraction and parsing into key value pairs. Can multipart encode data so files extraction and parsing into key value pairs. Can multipart encode data so files
can easily be sent in a HTTP request. can easily be sent in a HTTP request. Will emulate a range request if the server
does not support range requests.
REQUIREMENTS REQUIREMENTS
...@@ -53,6 +54,10 @@ Settings page is located at: ...@@ -53,6 +54,10 @@ Settings page is located at:
* IP Address to send all self server requests to. If left blank it will use the * IP Address to send all self server requests to. If left blank it will use the
same server as the request. If set to -1 it will use the host name instead of same server as the request. If set to -1 it will use the host name instead of
an IP address. This controls the output of httprl_build_url_self(). an IP address. This controls the output of httprl_build_url_self().
* Enable background callbacks. If disabled all background_callback keys will
be turned into callback & httprl_queue_background_callback will return NULL
and not queue up the request. Note that background callbacks will
automatically be disabled if the site is in maintenance mode.
API OVERVIEW API OVERVIEW
...@@ -71,6 +76,8 @@ httprl_queue_background_callback() ...@@ -71,6 +76,8 @@ httprl_queue_background_callback()
- Queue a special HTTP request (used for threading) in httprl_send_request(). - Queue a special HTTP request (used for threading) in httprl_send_request().
Other Functions: Other Functions:
httprl_is_background_callback_capable()
- See if httprl can issue a background callback.
httprl_background_processing() httprl_background_processing()
- Output text, close connection, continue processing in the background. - Output text, close connection, continue processing in the background.
httprl_strlen() httprl_strlen()
...@@ -116,6 +123,21 @@ Request http://drupal.org/. ...@@ -116,6 +123,21 @@ Request http://drupal.org/.
?> ?>
Request http://drupal.org/robots.txt and save it to tmp folder.
<?php
// Queue up the request.
httprl_request('http://drupal.org/robots.txt');
// Execute request.
$request = httprl_send_request();
// Save file if we got a 200 back.
if ($request['http://drupal.org/robots.txt']->code == 200) {
file_put_contents('/tmp/robots.txt', $request['http://drupal.org/robots.txt']->data);
}
?>
Request this servers own front page & the node page. Request this servers own front page & the node page.
<?php <?php
...@@ -432,6 +454,11 @@ Send 2 files in one field via a POST request. ...@@ -432,6 +454,11 @@ Send 2 files in one field via a POST request.
Use 2 threads to load up 4 different nodes. Use 2 threads to load up 4 different nodes.
<?php <?php
// Bail out here if background callbacks are disabled.
if (!httprl_is_background_callback_capable()) {
return FALSE;
}
// List of nodes to load; 241-244. // List of nodes to load; 241-244.
$nodes = array(241 => '', 242 => '', 243 => '', 244 => ''); $nodes = array(241 => '', 242 => '', 243 => '', 244 => '');
foreach ($nodes as $nid => &$node) { foreach ($nodes as $nid => &$node) {
...@@ -462,6 +489,11 @@ Run a function in the background. Notice that there is no return or printed key ...@@ -462,6 +489,11 @@ Run a function in the background. Notice that there is no return or printed key
in the callback options. in the callback options.
<?php <?php
// Bail out here if background callbacks are disabled.
if (!httprl_is_background_callback_capable()) {
return FALSE;
}
// Setup callback options array; call watchdog in the background. // Setup callback options array; call watchdog in the background.
$callback_options = array( $callback_options = array(
array( array(
...@@ -488,6 +520,11 @@ D6 & D7. ...@@ -488,6 +520,11 @@ D6 & D7.
// Show first module before running system_get_files_database(). // Show first module before running system_get_files_database().
echo httprl_pr(current($modules)); echo httprl_pr(current($modules));
// Bail out here if background callbacks are disabled.
if (!httprl_is_background_callback_capable()) {
return FALSE;
}
$callback_options = array( $callback_options = array(
array( array(
'function' => 'system_get_files_database', 'function' => 'system_get_files_database',
...@@ -515,6 +552,11 @@ Get 2 results from 2 different queries at the hook_boot bootstrap level in D6. ...@@ -515,6 +552,11 @@ Get 2 results from 2 different queries at the hook_boot bootstrap level in D6.
unset($x, $y); unset($x, $y);
// Bail out here if background callbacks are disabled.
if (!httprl_is_background_callback_capable()) {
return FALSE;
}
// Run above 2 queries and get the result via a background callback. // Run above 2 queries and get the result via a background callback.
$args = array( $args = array(
// First query. // First query.
...@@ -572,6 +614,12 @@ Get 2 results from 2 different queries at the hook_boot bootstrap level in D7. ...@@ -572,6 +614,12 @@ Get 2 results from 2 different queries at the hook_boot bootstrap level in D7.
echo $x . "<br \>\n" . $y . "<br \>\n"; echo $x . "<br \>\n" . $y . "<br \>\n";
unset($x, $y); unset($x, $y);
// Bail out here if background callbacks are disabled.
if (!httprl_is_background_callback_capable()) {
return FALSE;
}
// Run above 2 queries and get the result via a background callback. // Run above 2 queries and get the result via a background callback.
$args = array( $args = array(
// First query. // First query.
...@@ -661,6 +709,11 @@ non blocking background request. ...@@ -661,6 +709,11 @@ non blocking background request.
system_clear_cache_submit(); system_clear_cache_submit();
// Bail out here if background callbacks are disabled.
if (!httprl_is_background_callback_capable()) {
return FALSE;
}
// How to do it in a non blocking background request. // How to do it in a non blocking background request.
$args = array( $args = array(
array( array(
......
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