Hi,
i tried to use this module to improve stage_file_proxy, but somehow i can't figure how to get the raw data of a request.
Thought i should use the callback functionality, but $data is always just "1"
Also, the callback is called but the return value never reaches the main function.

<?php
function stage_file_proxy_cb($data) {
 
watchdog('stage_file_proxy', "data: %data", array("%data" => print_r($data),));
  return array(
'something' => "here");
}
function
_stage_file_proxy_fetch_httprl($url, $file_dir, $relative_path) {
 
$x = new stdClass();
 
$options = array(
   
//'method' => 'HEAD',
   
'callback' => array(
         array(
          
'function' => 'stage_file_proxy_cb',
          
'return' => &$x,
         ),
    )
  );
 
httprl_request($url, $options);
 
$request = httprl_send_request();
 
watchdog("stage_file_proxy", "fetching with httprl: %url <br /> data: %data <br /> callback: %callback", array("%url" => $url, "%data" => print_r($request), "%callback" => print_r($x)), WATCHDOG_DEBUG);
 
file_put_contents($file_dir . '/' . $relative_path, $request);
  return
TRUE;
}
?>

Comments

For the most part httprl has the same API as core's drupal_http_request(). So using httprl or core will have very similar looking code. The main difference between core and httprl is httprl returns an array of URLs.

<?php
function _stage_file_proxy_fetch_core($url, $file_dir, $relative_path) {
 
// Send off request.
 
$request = drupal_httprl_request($url);
 
// Log information.
 
watchdog("stage_file_proxy", "fetching with httprl: %url <br /> data: %data", array("%url" => $url, "%data" => print_r($request), WATCHDOG_DEBUG);
 
// Save File.
 
file_put_contents($file_dir . '/' . $relative_path, $request->data);
  return
TRUE;
}
function
_stage_file_proxy_fetch_httprl($url, $file_dir, $relative_path) {
 
// Queue URL.
 
httprl_request($url);
 
// Send off request.
 
$request = httprl_send_request();
 
// Log information.
 
watchdog("stage_file_proxy", "fetching with httprl: %url <br /> data: %data", array("%url" => $url, "%data" => print_r($request), WATCHDOG_DEBUG);
 
// Save File.
 
file_put_contents($file_dir . '/' . $relative_path, $request[$url]->data);
  return
TRUE;
}
?>

Callbacks are mainly useful with parallel requests.

Status:Active» Fixed
StatusFileSize
new4.36 KB

The following patch has been committed.

Changed a couple more things in the readme file.

Status:Fixed» Closed (fixed)

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