Commit 2955b7f6 authored by mikeytown2's avatar mikeytown2

Issue #1909120 by mikeytown2: Ping DB every 20 seconds to keep DB connection alive.

parent f62a7f18
......@@ -336,6 +336,7 @@ function httprl_set_default_options(&$options) {
'chunk_size_read' => 32768,
'chunk_size_write' => 1024,
'async_connect' => TRUE,
'ping_db' => 20,
);
// Adjust Time To First Byte Timeout if timeout is large and ttfb is default.
......@@ -901,6 +902,9 @@ function httprl_establish_stream_connection(&$result) {
* - stall_fread: TRUE or FALSE. If true once all fwrites have been done
* httprl_send_request() will return. You will need to call
* httprl_send_request() a second time to read the responses back.
* - ping_db: After X amount of time, ping the DB with a simple query in order
* to keep the connection alive. Default is every 20 seconds. Set to 0 to
* disable.
*
* @return array
* Array where key is the URL and the value is the return value from
......@@ -1073,6 +1077,9 @@ function httprl_send_request($results = NULL) {
// Record start time.
$start_time_this_run = $start_time_global = microtime(TRUE);
// Record the number of db pings done.
$ping_db_counts = array();
$full_bootstrap = httprl_drupal_full_bootstrap();
// Run the loop as long as we have a stream to read/write to.
$stream_select_timeout = 1;
......@@ -1094,6 +1101,19 @@ function httprl_send_request($results = NULL) {
$start_time_this_run = $now;
$global_time = $global_timeout - ($start_time_this_run - $start_time_global);
// See if the DB needs to be pinged.
$rounded_time = floor($elapsed_time);
if ( $full_bootstrap
&& !empty($result->options['ping_db'])
&& $rounded_time >= $result->options['ping_db']
&& $rounded_time % $result->options['ping_db'] == 0
&& empty($ping_db_counts[$rounded_time])
) {
$empty_array = array();
system_get_files_database($empty_array, 'ping_db');
$ping_db_counts[$rounded_time] = 1;
}
// Inspect each stream, checking for timeouts and connection limits.
foreach ($responses as $id => &$result) {
// See if function timed out.
......
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