Getting this notice: Notice: Undefined index: url in httprl_send_request() (line 491 of /sites/all/modules/httprl/httprl.module).

I have a script that goes through URLs 100 at a time and gets the page data. I guess something is happening when it is mapping the redirects.

I logged the variables to see what the values were in the failed cases. Here's an example if it helps (logged on line 491 above the if statement):
$info['redirect_url'][0] - http://toppietrips.com/
$values['url'] - undefined
$values['redirect_url'][0] - http://www.mobilephonefinder.com.au/mobile-phones/htc/

Files: 

Comments

StatusFileSize
new679 bytes

That's a strange error you encountered. Reason is I set the URL in the array. Code in question:

<?php
 
// Check to see if any of the requests where a redirect.
 
$redirects = array();
  foreach (
$responses as $id => $result) {
    if (!empty(
$result->redirect_url)) {
     
$redirects[] = array(
       
'redirect_url' => array($result->redirect_url[0]),
       
'redirect_code' => array($result->redirect_code[0]),
       
'id' => $id,
       
'url' => $result->url,
      );
      unset(
$responses[$id]);
    }
  }
 
// Put redirects into the correct request url.
 
if (!empty($redirects)) {
   
// Get nested redirect info.
   
foreach ($redirects as $key => $info) {
      foreach (
$redirects as $next_key => $values) {
        if (
$info['redirect_url'][0] == $values['url']) { // ***line 491***
         
$redirects[$key]['redirect_url'][] = $values['redirect_url'][0];
         
$redirects[$key]['redirect_code'][] = $values['redirect_code'][0];
          unset(
$redirects[$next_key]);
          break;
        }
      }
    }
  ...
  }
?>

My only guess is that unsetting the $redirects in the loop is causing issues. Patch below addresses this theory. Please test and let me know.

Status:Active» Needs review

Thanks for the fast reply.

This patch doesn't seem to help though, as $values is set, just not the url value for some reason. I will try and put together a test set of urls that causes this problem when I get a chance.

Cheers.

Status:Needs review» Needs work

ok, I finally got to testing this, and here is a snippet that will give the error, also, it seems there is no response for the url in this case either.

<?php
$urls
= array(
 
'http://modifiedstreetcars.com', // this website is set to redirect non-www to www. and it seems to cause a problem
 
'http://www.mod-store.com.au',
);
foreach (
$urls as $url) {
 
httprl_request($url, array('blocking' => TRUE));
}
// process the requests
$request = httprl_send_request();
foreach (
$request as $url => $response) {
 
watchdog('httprl test', 'URL: '.$url, NULL);
}
?>

After running this, I only get a response for the second URL, and there is notices in the log.

Any update on this at all?

I did some debugging, and the headers Host variable is not being updated to the redirect host, so I made the following change. Not sure if there is a problem with always overriding this variable, but works now for my tests.

<?php
if (empty($options['headers']['Host'])) { // line 165
 
$options['headers']['Host'] = $uri['host'];
}
// to just
$options['headers']['Host'] = $uri['host']; // no check, just overwrite value.
?>

Status:Needs work» Needs review

Status:Needs review» Fixed
StatusFileSize
new569 bytes

I actually use that code there; but thanks for pointing me in the right place. I've fixed the code, this patch has been committed.

Great thanks mate, this module makes my project much more efficient. Keep up the good work.

Status:Fixed» Closed (fixed)

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