I am finding the following errors in my logs periodically, seems to be happening with Google crawling my site:

implode() [function.implode]: Invalid arguments passed in /var/www/drupal-6.13/sites/all/modules/uc_upsell/uc_upsell_core.inc on line 238.

array_intersect() [function.array-intersect]: Argument #2 is not an array in /var/www/drupal-6.13/sites/all/modules/uc_upsell/uc_upsell_core.inc on line 272.

Kinda weird cause it happens on random products and whenever I go to the one producing the previous error it returns fine.
Any ideas? Oh and here is a fun way to see the errors, google "uc_upsell_core.inc on line 238" or "uc_upsell_core.inc on line 272" you can look at a cached page from my site!.. hopefully I fixed that by changing error reporting to database only! doh.

Comments

torgospizza’s picture

AFAIK, Google shouldn't even be crawling module pages? Do you have a modified .htaccess file or anything? I can't say I've ever seen that and I'm not sure why you would have crawlers checking out files from within sites/all/modules - but perhaps that's just something I haven't seen yet?

I'll see if I can wrap that in a conditional statement that'll prevent rogue "views" of that file from throwing an error. Very strange.

Rainman’s picture

Hey tP!

Google is crawling my product pages and in the process bringing up the upsell block. that is what I traced the errors back to, sorry if I wasn't clear.

torgospizza’s picture

Oh.. interesting.. Well, it still should not throw that error, because crawling a page is the same as viewing them.

The line in question is a function that combines taxonomy terms. Are you using the "show related by taxonomy" functionality at all? It also seems to me that the terms list was never built for the Upsell module. At around line 272, make it look like this:

$allterms = cache_get('uc_upsell_terms');
$intersect = array_intersect($node_tids, unserialize($allterms->data));

drupal_set_message(print_r($allterms, true));

Also, quick question: are you using any kind of cache module such as memcache or cacherouter? If so, then it's the "unserialize" part of the function that is probably causing the error. See if you can reproduce this error by simply browsing a product page, and then se what happens when you remove unserialize() from the method.

I might be better off just wrapping that entire thing in a conditional, to make sure it gets something back from cache_get().

Rainman’s picture

Here is an example from my log, hopefully make more sense

Details
Type php 
Date Thursday, August 20, 2009 - 02:45 
User Anonymous 
Location http://www.rainmanweather.com/site/products/WS-9117U-IT-Wireless-Thermometer 
Referrer  
Message implode() [<a href='function.implode'>function.implode</a>]: Invalid arguments passed in /var/www/drupal-6.13/sites/all/modules/uc_upsell/uc_upsell_core.inc on line 238. 
Severity error 
Hostname 66.249.71.46 
Operations

Details
Type php 
Date Thursday, August 20, 2009 - 02:45 
User Anonymous 
Location http://www.rainmanweather.com/site/products/WS-9117U-IT-Wireless-Thermometer 
Referrer  
Message array_intersect() [<a href='function.array-intersect'>function.array-intersect</a>]: Argument #2 is not an array in /var/www/drupal-6.13/sites/all/modules/uc_upsell/uc_upsell_core.inc on line 272. 
Severity error 
Hostname 66.249.71.46 
Operations 
torgospizza’s picture

Yeah that makes sense based on what I said in #3 :)

Rainman’s picture

The line in question is a function that combines taxonomy terms. Are you using the "show related by taxonomy" functionality at all?

Also, quick question: are you using any kind of cache module such as memcache or cacherouter? If so, then it's the "unserialize" part of the function that is probably causing the error. See if you can reproduce this error by simply browsing a product page, and then se what happens when you remove unserialize() from the method.

I am using - Add: Displays products specified by Node Edit Form, plus nodes related by taxonomy, then randoms if needed. so I think yes on #1

I am using apc, I think that would work the same for cache as the others you mentioned. I'll give it a try on my test site.

And, my bad, gotta slow down w/ crossing posts:) I'll give all this a try in a bit

torgospizza’s picture

Well APC is an opcode compiler, that wouldn't affect the way data is stored in the cache tables. Something like memcache would, though.

If the drupal_set_message() doesn't return anything then that means, for whatever reason, that your taxonomy term variable never got cached. It should be a serialized array in the variable table.

I can do 2 things:
1) Check during the array_intersect() to make sure something comes back.
2) If nothing comes back, recreate it on the fly. Or at least queue it to be created on next cron run.

Are you using cron? I think you might need to run cron to make sure that the terms get created. I'll double-check on that but I'm pretty sure that's when the array gets built.

// From uc_upsell.module (line 76)
/** 
 * Implementation of hook_cron
 */
function uc_upsell_cron() {
  uc_upsell_compute_terms();
}
torgospizza’s picture

I could also add one other thing:

3) In the admin/store/settings/upsell page, where it has the option for how Taxonomy-related products are managed, show an error msg there if the cached array has 0 items or doesn't exist. That way you can recreate it right there from within the admin UI and not have to bother running Cron.

Rainman’s picture

OK got to testing. I am using cron, and you are probably onto something there. looks like the cache cleared prior to the crawler hitting.

about an hour before:

page not found 08/20/2009 - 01:25 sites/default/files/js/js_d67df142afe805faa917a0cb9e ...
page not found 08/20/2009 - 01:25 sites/default/files/js/js_9c8c22e10f2fe04c34da8c5b40 ...
page not found 08/20/2009 - 01:25 sites/default/files/css/css_4deb0c0e129ff0cca163b054 ...

but I also see cron running twice before the crawler/errors, hmm.

anyhow, here is the output from testing with and without unserialize()

stdClass Object ( [data] => a:25:{i:0;i:14;i:1;i:15;i:2;i:25;i:3;i:17;i:4;i:24;i:5;i:10;i:6;i:16;i:7;i:18;i:8;i:4;i:9;i:6;i:10;i:28;i:11;i:29;i:12;i:22;i:13;i:23;i:14;i:9;i:15;i:36;i:16;i:27;i:17;i:11;i:18;i:20;i:19;i:1;i:20;i:8;i:21;i:30;i:22;i:34;i:23;i:35;i:24;i:32;} [created] => 1251177346 [headers] => [expire] => -1 [serialized] => 0 ) 
stdClass Object ( [data] => a:25:{i:0;i:14;i:1;i:15;i:2;i:25;i:3;i:17;i:4;i:24;i:5;i:10;i:6;i:16;i:7;i:18;i:8;i:4;i:9;i:6;i:10;i:28;i:11;i:29;i:12;i:22;i:13;i:23;i:14;i:9;i:15;i:36;i:16;i:27;i:17;i:11;i:18;i:20;i:19;i:1;i:20;i:8;i:21;i:30;i:22;i:34;i:23;i:35;i:24;i:32;} [created] => 1251177346 [headers] => [expire] => -1 [serialized] => 0 ) 
stdClass Object ( [data] => a:25:{i:0;i:14;i:1;i:15;i:2;i:25;i:3;i:17;i:4;i:24;i:5;i:10;i:6;i:16;i:7;i:18;i:8;i:4;i:9;i:6;i:10;i:28;i:11;i:29;i:12;i:22;i:13;i:23;i:14;i:9;i:15;i:36;i:16;i:27;i:17;i:11;i:18;i:20;i:19;i:1;i:20;i:8;i:21;i:30;i:22;i:34;i:23;i:35;i:24;i:32;} [created] => 1251177346 [headers] => [expire] => -1 [serialized] => 0 ) 
stdClass Object ( [data] => a:25:{i:0;i:14;i:1;i:15;i:2;i:25;i:3;i:17;i:4;i:24;i:5;i:10;i:6;i:16;i:7;i:18;i:8;i:4;i:9;i:6;i:10;i:28;i:11;i:29;i:12;i:22;i:13;i:23;i:14;i:9;i:15;i:36;i:16;i:27;i:17;i:11;i:18;i:20;i:19;i:1;i:20;i:8;i:21;i:30;i:22;i:34;i:23;i:35;i:24;i:32;} [created] => 1251177346 [headers] => [expire] => -1 [serialized] => 0 ) 
stdClass Object ( [data] => a:25:{i:0;i:14;i:1;i:15;i:2;i:25;i:3;i:17;i:4;i:24;i:5;i:10;i:6;i:16;i:7;i:18;i:8;i:4;i:9;i:6;i:10;i:28;i:11;i:29;i:12;i:22;i:13;i:23;i:14;i:9;i:15;i:36;i:16;i:27;i:17;i:11;i:18;i:20;i:19;i:1;i:20;i:8;i:21;i:30;i:22;i:34;i:23;i:35;i:24;i:32;} [created] => 1251177346 [headers] => [expire] => -1 [serialized] => 0 ) 


stdClass Object ( [data] => a:25:{i:0;i:14;i:1;i:15;i:2;i:25;i:3;i:17;i:4;i:24;i:5;i:10;i:6;i:16;i:7;i:18;i:8;i:4;i:9;i:6;i:10;i:28;i:11;i:29;i:12;i:22;i:13;i:23;i:14;i:9;i:15;i:36;i:16;i:27;i:17;i:11;i:18;i:20;i:19;i:1;i:20;i:8;i:21;i:30;i:22;i:34;i:23;i:35;i:24;i:32;} [created] => 1251177346 [headers] => [expire] => -1 [serialized] => 0 ) 
stdClass Object ( [data] => a:25:{i:0;i:14;i:1;i:15;i:2;i:25;i:3;i:17;i:4;i:24;i:5;i:10;i:6;i:16;i:7;i:18;i:8;i:4;i:9;i:6;i:10;i:28;i:11;i:29;i:12;i:22;i:13;i:23;i:14;i:9;i:15;i:36;i:16;i:27;i:17;i:11;i:18;i:20;i:19;i:1;i:20;i:8;i:21;i:30;i:22;i:34;i:23;i:35;i:24;i:32;} [created] => 1251177346 [headers] => [expire] => -1 [serialized] => 0 ) 
stdClass Object ( [data] => a:25:{i:0;i:14;i:1;i:15;i:2;i:25;i:3;i:17;i:4;i:24;i:5;i:10;i:6;i:16;i:7;i:18;i:8;i:4;i:9;i:6;i:10;i:28;i:11;i:29;i:12;i:22;i:13;i:23;i:14;i:9;i:15;i:36;i:16;i:27;i:17;i:11;i:18;i:20;i:19;i:1;i:20;i:8;i:21;i:30;i:22;i:34;i:23;i:35;i:24;i:32;} [created] => 1251177346 [headers] => [expire] => -1 [serialized] => 0 ) 
stdClass Object ( [data] => a:25:{i:0;i:14;i:1;i:15;i:2;i:25;i:3;i:17;i:4;i:24;i:5;i:10;i:6;i:16;i:7;i:18;i:8;i:4;i:9;i:6;i:10;i:28;i:11;i:29;i:12;i:22;i:13;i:23;i:14;i:9;i:15;i:36;i:16;i:27;i:17;i:11;i:18;i:20;i:19;i:1;i:20;i:8;i:21;i:30;i:22;i:34;i:23;i:35;i:24;i:32;} [created] => 1251177346 [headers] => [expire] => -1 [serialized] => 0 ) 
stdClass Object ( [data] => a:25:{i:0;i:14;i:1;i:15;i:2;i:25;i:3;i:17;i:4;i:24;i:5;i:10;i:6;i:16;i:7;i:18;i:8;i:4;i:9;i:6;i:10;i:28;i:11;i:29;i:12;i:22;i:13;i:23;i:14;i:9;i:15;i:36;i:16;i:27;i:17;i:11;i:18;i:20;i:19;i:1;i:20;i:8;i:21;i:30;i:22;i:34;i:23;i:35;i:24;i:32;} [created] => 1251177346 [headers] => [expire] => -1 [serialized] => 0 ) 
torgospizza’s picture

Yeah that's probably what it is. When you rebuilt the cache, did the errors go away?

I'll have to put something in there that just checks to make sure the cached var exists, and if not, rebuild it.

Rainman’s picture

Well I am assuming the cache rebuilt itself in response to the page load. ofcourse the crawler kept on crawling and no more errors showed up. this has been random showing up generally in the middle of the night when traffic is low, a single set of errors and then everything fine till next time. so the pattern seems to fit.

torgospizza’s picture

Yeah, well cache only gets rebuilt if something is set to do it. How does your cache get erased? If the cache variable gets built once, it shouldn't need to ever be rebuilt unless there is a change or cron runs, which is how it's setup to work. So if for some reason your cache table gets borked before cron runs, then yeah those errors would get thrown. The best way to avoid that, I think, is to check to see if the cached array exists before attempting to do anything on it; and if it doesn't exist, then create it. I just don't want to cause any interruptions on a site that has tons of taxonomy terms, ya know?

Rainman’s picture

Understood about causing interruption with building the array. I was assuming the cache got rebuilt anyways in response to the error as it didn't show up again in that timeframe.. so you would just be heading off the inevitable if that's true.

as far a how the cache getting erased, I honestly don't know. I was assuming it had timed out or something along those lines was normal. perhaps httpd restarted, would that do it? I can check logs to verify.

Notice I make alot of assumptions, still a newb:) thanks for looking into this!

torgospizza’s picture

No, none of that would cause the cache to be cleared, AFAIK. The best solution, probably, is just to make sure the array exists and contains items, otherwise recreate it. That should solve those errors. Other than that I think you can safely ignore them... but I'd still like to get it figured out and fixed.

torgospizza’s picture

I'll be looking at this next.

torgospizza’s picture

Status: Active » Needs review

This issue is related to comment #11 in #562082: Related Product associations do not take precedence with Add based on Taxonomy

http://drupal.org/node/562082#comment-1988348

I added a conditional statement around this bit of code - that should resolve the issue.

Rainman’s picture

ah, ok good deal. I have not seen it show up again using the past couple of devs.

torgospizza’s picture

Status: Needs review » Fixed

Great! Thanks for letting me know. :) Marking as fixed!

Status: Fixed » Closed (fixed)

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