You are here

function _httprl_run_functions_once_on_shutdown_array_cache in HTTP Parallel Request & Threading Library 6

Same name and namespace in other branches
  1. 7 httprl.module \_httprl_run_functions_once_on_shutdown_array_cache()

Cache function helper. Combine duplicates & run them in a shutdown function.

Parameters

callable $args: The callable to be called.

1 call to _httprl_run_functions_once_on_shutdown_array_cache()
httprl_call_user_func_array_cache in ./httprl.module
Cache a function; regenerate return value in the background.

File

./httprl.module, line 3652
HTTP Parallel Request Library module.

Code

function _httprl_run_functions_once_on_shutdown_array_cache($args = array()) {
  $run_list =& drupal_static('_httprl_run_functions_once_on_shutdown_array_cache', array());
  if (!empty($args)) {
    if (empty($run_list)) {

      // Register a shutdown function is this is the first time being ran.
      register_shutdown_function('_httprl_run_functions_once_on_shutdown_array_cache');
    }
    $run_list[] = $args;
  }
  else {
    unset($args);
    $will_run = array();
    $already_ran = array();
    foreach ($run_list as $args) {
      if (empty($args)) {
        continue;
      }
      if (is_string($args[0])) {
        $cid = __FUNCTION__ . ':' . $args[0] . ':' . drupal_hash_base64(serialize(array(
          $args[1],
        )));
      }
      else {
        $cid = __FUNCTION__ . ':' . drupal_hash_base64(serialize(array(
          $args[0],
          $args[1],
        )));
      }
      if (empty($already_ran[$cid])) {
        $already_ran[$cid] = TRUE;
        $will_run[] = $args;
      }
    }
    if (!empty($will_run)) {
      httprl_call_user_func_array_async('_httprl_run_cache_functions', array(
        $will_run,
      ));
    }
  }
}