Piwik Auto Archive

I am trying to set up Auto Archiving.

I followed instructions from here:

http://piwik.org/docs/setup-auto-archiving/

So I created piwik-archive with this comand:

sudo nano /etc/cron.d/piwik-archive

and set this cron job:

MAILTO="youremail@example.com"
5 * * * * www-data /usr/bin/php5 var/www/piwik/console core:archive --url=http://mysite.info/piwik/ > /var/www/piwik/piwik-archive.log

But this doesn’t work if I set user to “www-data” like above, or I skip that param like here:

MAILTO="youremail@example.com"
5 * * * * /usr/bin/php5 var/www/piwik/console core:archive --url=http://mysite.info/piwik/ > /var/www/piwik/piwik-archive.log

Cron job only works if I set user to “root” like here:

MAILTO="youremail@example.com"
5 * * * * root /usr/bin/php5 var/www/piwik/console core:archive --url=http://mysite.info/piwik/ > /var/www/piwik/piwik-archive.log

I am checking does it works or not by checking piwik-archive.log, if I don’t set user to “root” piwik-archive.log file will not be outputted at all.

But even if I set user to “root” and under General settings set those two options:
And I set “Allow Piwik archiving to trigger when reports are viewed from the browser” to NO
and “Reports for today (or any other Date Range including today) will be processed at most every” to 3600

I think that it’s still doesn’t work.

I am calling one API from php:

    $url = "http://mysite.info/piwik/";
    $url .= "?module=API&method=VisitsSummary.get";
    $url .= "&idSite=1&period=mounth&date=today";
    $url .= "&format=PHP&filter_limit=20";
    $url .= "&token_auth=85d11217db9asda3b573146f93766f79f27";
    $fetched = file_get_contents($url);
    $content = unserialize($fetched);
    var_dump($content);

And I am get this results for example:

Array
(
[nb_uniq_visitors] => 3
[nb_users] => 0
[nb_visits] => 6
[nb_actions] => 36
[nb_visits_converted] => 0
[bounce_count] => 4
[sum_visit_length] => 3062
[max_actions] => 21
[bounce_rate] => 67%
[nb_actions_per_visit] => 6
[avg_time_on_site] => 510
)

But there is more visits and actions, if I changed option “Allow Piwik archiving to trigger when reports are viewed from the browser” to NO
and then call this API I will get this:

Array
(
[nb_uniq_visitors] => 3
[nb_users] => 0
[nb_visits] => 7
[nb_actions] => 37
[nb_visits_converted] => 0
[bounce_count] => 5
[sum_visit_length] => 3062
[max_actions] => 21
[bounce_rate] => 71%
[nb_actions_per_visit] => 5.3
[avg_time_on_site] => 437
)

So can anyone help me here, I need to have this set up until Sunday. I am testing this on my Test site and on Sunday it should be set on Production.