Copy the syntax of call_user_func_array() to make threading simpler to use.

Also add a note that PHP 5.4+ removed the pass by reference capabilities so that no longer works inside of HTTPRL if using a newer version of PHP.

Comments

mikeytown2’s picture

Still working on it but I have some initial work done.


/**
 * Run function in different process.
 *
 * @see call_user_func_array()
 *
 * @param callback
 *   The callable to be called.
 * @param param_arr
 *   The parameters to be passed to the callback, as an indexed array.
 * @param $return
 *   Variable used to return data.
 * @param $httprl_options
 *   Options to pass along to httprl_queue_background_callback.
 */
function run_in_new_process($callback, $param_arr, &$return = NULL, $httprl_options = array()) {
  // Setup callback options array.
  $callback_options = array(
    array(
      'function' => $callback,
      // Setup options array.
      'options' => $httprl_options,
    ),
  );
  $callback_options = array_merge($callback_options, $param_arr);

  if (!is_null($return)) {
    $callback_options[0]['return'] = &$return;
  }
  // Queue up the request.
  httprl_queue_background_callback($callback_options);
}

run_in_new_process('watchdog', array('test', 'test message'));
$b = '';
run_in_new_process('menu_get_item', array('admin'), $b, array('domain_connections' => 60, 'timeout' => 600));
httprl_send_request();

echo httprl_pr($b);

Next step is working on batch processing

function array_chunk_vertical($data, $columns) {
  $n = count($data) ;
  $per_column = floor($n / $columns) ;
  $rest = $n % $columns ;

  // The map
  $per_columns = array( ) ;
  for ( $i = 0 ; $i < $columns ; $i++ ) {
    $per_columns[$i] = $per_column + ($i < $rest ? 1 : 0) ;
  }

  $tabular = array( ) ;
  foreach ( $per_columns as $rows ) {
    for ( $i = 0 ; $i < $rows ; $i++ ) {
      $tabular[$i][ ] = array_shift($data) ;
    }
  }

  return $tabular ;
}
mikeytown2’s picture

Figured this out... nice
http://php.net/references.return

mikeytown2’s picture

Syntax is now very similar to call_user_func_array().

/**
 * Queue Callback to run In a New Process.
 *
 * @see call_user_func_array()
 *
 * @param callback
 *   The callable to be called.
 * @param param_arr
 *   The parameters to be passed to the callback, as an indexed array.
 * @param $return
 *   Set to TRUE if you want something returned.
 * @param $httprl_options
 *   Options to pass along to httprl_queue_background_callback.
 * @return
 *   Reference to the return varible OR NULL if $return is FALSE.
 */
function &httprl_qcinp($callback, $param_arr = array(), $return = TRUE, $httprl_options = array()) {
  $return_var = NULL;

  // Setup callback options array.
  $callback_options = array(
    array(
      'function' => $callback,
      // Setup options array.
      'options' => $httprl_options,
    ),
  );
  $callback_options = array_merge($callback_options, $param_arr);

  if ($return) {
    $return_var = '';
    $callback_options[0]['return'] = &$return_var;
  }
  // Queue up the request.
  httprl_queue_background_callback($callback_options);

  return $return_var;
}

$a = &httprl_qcinp('menu_get_item', array('admin/reports'));
$b = call_user_func_array('menu_get_item', array('admin/reports'));
httprl_send_request();
echo httprl_pr($a, $b);

mikeytown2’s picture

Component: Code » Documentation
Category: Feature request » Support request
StatusFileSize
new5.11 KB

Patch has been committed. Now need to document it.

mikeytown2’s picture

Status: Active » Fixed
StatusFileSize
new3.13 KB

Following patch has been committed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.