I’m working hard on this issue but I still can’t figuring out what is happening. Any help welcomed.
First I displayed the request error message by modifying archive.php like this:
$response = $this->request($url);
$test_unserialized_response = unserialize($response);
if(empty($response) || (!$test_unserialized_response)) {
// cancel the succesful run flag
Piwik_SetOption( $this->lastRunKey($idsite, "day"), 0 );
$this->log("WARNING: Empty or invalid response for website id $idsite, ".$timerWebsite.", skipping");
$this->log("URL: ".$url);
var_dump($response);
$skipped++;
continue;
}
Then my archive script logged what I expected, a nasty nginx error:
<html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.0.5</center>
</body>
</html>
As I am new at tunning nginx and php-fpm, I reviewed the basic parameters that could create such a problem: max_execution_time and memory limits are far above what I need.
Funny stuff: I don’t have any other errors on the rest of the script. If I ignore the error and I let the archive script continue, I don’t have any errors on week, month and year archiving:
...
[2012-03-11 18:54:51] [29d97439] ---------------------------
[2012-03-11 18:54:51] [29d97439] START
[2012-03-11 18:54:51] [29d97439] Starting Piwik reports archiving...
PHP Notice: unserialize(): Error at offset 0 of 170 bytes in /piwik/misc/cron/archive.php on line 265
PHP Warning: end() expects parameter 1 to be array, boolean given in /piwik/misc/cron/archive.php on line 266
PHP Warning: array_sum() expects parameter 1 to be array, boolean given in /piwik/misc/cron/archive.php on line 279
[2012-03-11 18:58:00] [29d97439] Archived website id = 1, period = day, Time elapsed: 189.153s
[2012-03-11 18:58:43] [29d97439] Archived website id = 1, period = week, 410866 visits, Time elapsed: 43.665s
[2012-03-11 19:03:04] [29d97439] Archived website id = 1, period = month, 1587306 visits, Time elapsed: 260.771s
[2012-03-11 19:05:11] [29d97439] Archived website id = 1, period = year, 8815130 visits, Time elapsed: 126.841s
[2012-03-11 19:05:11] [29d97439] Archived website id = 1, today = visits, 4 API requests, Time elapsed: 620.433s [1/1 done]
[2012-03-11 19:05:11] [29d97439] Done archiving!
...
In the php-fpm log:
WARNING: [pool www] child 29524 exited on signal 11 (SIGSEGV)
In nginx log:
[error] 26863#0: *1563613 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: [...], server: [...], request: "GET /index.php?module=API&method=VisitsSummary.getVisits&idSite=1&period=day&date=last2&format=php&token_auth=[...]&trigger=archivephp HTTP/1.1", upstream: "fastcgi://unix:/tmp/php5-fpm.sock:", host: [...]
In syslog:
kernel: [12893927.352532] php5-fpm[10685]: segfault at 7f60cff2b809 ip 00000000006b49c9 sp 00007fff9add9440 error 4 in php5-fpm[400000+756000]
Before the crash, the last request I see on mysql side is:
SELECT
log_link_visit_action.custom_var_k5 AS custom_var_k5, log_link_visit_action.custom_var_v5 AS custom_var_v5, ROUND(AVG(log_link_visit_action.custom_var_v2),2) as `27`,
count(distinct log_link_visit_action.idvisit) as `2`,
count(distinct log_link_visit_action.idvisitor) as `1`,
count(*) as `3`
FROM
piwik_log_link_visit_action AS log_link_visit_action
WHERE
log_link_visit_action.server_time >= '2012-03-10 23:00:00'
AND log_link_visit_action.server_time <= '2012-03-11 22:59:59'
AND log_link_visit_action.idsite = '1'
AND log_link_visit_action.custom_var_k5 != ''
GROUP BY
log_link_visit_action.custom_var_k5, log_link_visit_action.custom_var_v5
Any help is realy welcomed because I’m going crazy right now… 
Thanks