Commit 5defa1f9 authored by mikeytown2's avatar mikeytown2

Issue #1891676 by mikeytown2: Fix global timeout issues and php timeout issues...

Issue #1891676 by mikeytown2: Fix global timeout issues and php timeout issues in background callbacks.
parent 641d1925
......@@ -50,6 +50,15 @@ function httprl_async_page() {
// Release the lock.
httprl_lock_release($_POST['temp_key']);
// Set time limit.
if (isset($_POST['php_timeout']) && is_numeric($_POST['php_timeout'])) {
// Copy of drupal_set_time_limit().
if (function_exists('set_time_limit')) {
@set_time_limit($_POST['php_timeout']);
}
}
// Extract Data.
$args = unserialize($_POST['args']);
// Run the function.
......
......@@ -337,6 +337,10 @@ function httprl_set_default_options(&$options) {
if ($options['timeout'] > httprl_variable_get('httprl_timeout', HTTPRL_TIMEOUT) && $options['ttfb_timeout'] == httprl_variable_get('httprl_ttfb_timeout', HTTPRL_TTFB_TIMEOUT)) {
$options['ttfb_timeout'] = $options['timeout'] - max(1, httprl_variable_get('httprl_timeout', HTTPRL_TIMEOUT) - httprl_variable_get('httprl_ttfb_timeout', HTTPRL_TTFB_TIMEOUT));
}
// Adjust Global Timeout if timeout is large and global_timeout is default.
if ($options['timeout'] > httprl_variable_get('httprl_timeout', HTTPRL_TIMEOUT) && $options['global_timeout'] == httprl_variable_get('httprl_global_timeout', HTTPRL_GLOBAL_TIMEOUT)) {
$options['global_timeout'] = $options['timeout'] + max(1, httprl_variable_get('httprl_global_timeout', HTTPRL_GLOBAL_TIMEOUT) - httprl_variable_get('httprl_timeout', HTTPRL_TIMEOUT));
}
// Merge the default headers.
// Set user agent to drupal.
......@@ -1715,7 +1719,7 @@ function httprl_post_processing($id, &$responses, &$output, $time_left = NULL) {
httprl_decode_data($result);
// If this is a background callback request, extract the data and return.
if (isset($result->options['internal_states']['background_function_return']) && isset($result->headers['content-type']) && $result->headers['content-type'] == 'application/x-www-form-urlencoded') {
if (isset($result->options['internal_states']) && array_key_exists('background_function_return', $result->options['internal_states']) && isset($result->headers['content-type']) && strpos($result->headers['content-type'], 'application/x-www-form-urlencoded') !== FALSE) {
httprl_extract_background_callback_data($result);
unset($responses[$id]);
return;
......@@ -1952,6 +1956,7 @@ function httprl_queue_background_callback(&$args, &$result = NULL) {
'master_key' => hash('sha512', httprl_drupal_get_private_key()),
'temp_key' => $id,
'mode' => $mode,
'php_timeout' => max($times),
'function' => $callback_options['function'],
'args' => serialize($args),
),
......@@ -2600,11 +2605,18 @@ function httprl_run_function($function, &$input_args) {
$php_errormsg = '';
// Run function.
if (function_exists($function)) {
$return = call_user_func_array($function, $args);
$return = NULL;
// Do not let an exception cause issues.
try {
if (function_exists($function)) {
$return = call_user_func_array($function, $args);
}
else {
$php_errormsg = 'Recoverable Fatal error: Call to undefined function ' . $function . '()';
}
}
else {
$php_errormsg = 'Recoverable Fatal error: Call to undefined function ' . $function . '()';
catch (Exception $e) {
$php_errormsg = $e;
}
$printed = ob_get_contents();
......
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