Can't run archive.php after upgrade from 2.2.0 -> 2.11.2

I can’t run the misc/cron/archive.php?token_auth= script after upgrading Piwik from 2.2.0 -> 2.11.2. Here are the errors I get:


INFO Piwik\Access[2015-03-12 19:45:57] [edab5] --------------------------- INFO Piwik\Access[2015-03-12 19:45:57] [edab5] INIT INFO Piwik\Access[2015-03-12 19:45:57] [edab5] Piwik is installed at: https://www.domai.com/piwik/index.php INFO Piwik\Access[2015-03-12 19:45:57] [edab5] Running Piwik 2.11.2 as Super User ERROR Piwik\Access[2015-03-12 19:45:57] [edab5] The Piwik URL https://www.domai.com/piwik/index.php does not seem to be pointing to a Piwik server. Response was 'Got invalid response from API request: https://www.domai.com/piwik/index.php?module=API&method=API.getDefaultMetricTranslations&format=original&serialize=1&trigger=archivephp. Response was 'curl_exec: SSL peer certificate or SSH remote key was not OK. Hostname requested was: www.domai.com''.
Fatal error: Uncaught exception 'Exception' with message 'The Piwik URL https://www.domai.com/piwik/index.php does not seem to be pointing to a Piwik server. Response was 'Got invalid response from API request: https://www.domai.com/piwik/index.php?module=API&method=API.getDefaultMetricTranslations&format=original&serialize=1&trigger=archivephp. Response was 'curl_exec: SSL peer certificate or SSH remote key was not OK. Hostname requested was: www.domai.com''.' in /home/piwik/core/CronArchive.php:406 Stack trace: #0 /home/piwik/core/CronArchive.php(1204): Piwik\CronArchive->logFatalError('The Piwik URL h...') #1 /home/piwik/core/CronArchive.php(250): Piwik\CronArchive->checkPiwikUrlIsValid() #2 /home/piwik/core/CronArchive.php(237): Piwik\CronArchive->init() #3 /home/piwik/core/Access.php(454): Piwik\{closure}() #4 /home/piwik/core/CronArchive.php(241): Piwik\ in /home/piwik/core/CronArchive.php on line 406

Fatal error: Uncaught exception 'Zend_Session_Exception' with message 'Session must be started before any output has been sent to the browser; output started in /home/piwik/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php/93' in /home/piwik/libs/Zend/Session.php:443 Stack trace: #0 /home/piwik/libs/Zend/Session/Namespace.php(143): Zend_Session::start(true) #1 /home/piwik/core/Session/SessionNamespace.php(34): Zend_Session_Namespace->__construct('CorePluginsAdmi...', false) #2 /home/piwik/core/Nonce.php(39): Piwik\Session\SessionNamespace->__construct('CorePluginsAdmi...') #3 /home/piwik/plugins/CorePluginsAdmin/Controller.php(385): Piwik\Nonce::getNonce('CorePluginsAdmi...') #4 [internal function]: Piwik\Plugins\CorePluginsAdmin\Controller->safemode(Array) #5 /home/piwik/core/FrontController.php(604): call_user_func_array(Array, Array) #6 /home/ in /home/piwik/libs/Zend/Session.php on line 443

Any suggestions?

Is there something that can be modified inside archive.php to disable it form using SSL and thus avoiding this error?

Hi there,

Yes, you can add the the following parameter to your ./console core:archive call:


--accept-invalid-ssl-certificate

Additionally, I belive the archive.php script has been deprecated in preference to console core:archive.

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

Yes, you can add the the following parameter to your ./console core:archive call:

–accept-invalid-ssl-certificate

I tried that but it still gives the same errors. I tried adding it to line 58 like this:


array_unshift($_SERVER['argv'], 'core:archive --accept-invalid-ssl-certificate');

Maybe I’m doing it wrong?

As for:

Additionally, I belive the archive.php script has been deprecated in preference to console core:archive.

Yes, I am aware of this, but unfortunately my server would not allow me to run console core:archive - something to do with no SSH on the server.

So I’m in a bit of a bind - can’t run console nor archive.php.

What’s the problem/ error message with runnning the console ?

I am running the console from a bash file, as I can only add files to crontab, without commands. My bash file looks like this:


#!/bin/bash

php /home/piwik/console core:archive --url=http://domain.name/piwik/ > /home/piwik/piwik-archive-output.log

Here is the error message when trying to execute the bash file which executes the console:


sh: /bin/uname: Permission denied
sh: /bin/uname: Permission denied

ERROR CoreConsole[2015-03-19 14:22:23] The Piwik URL http://domain.name/piwik/index.php does not seem to be pointing to a Piwik server. Response was 'sh: /bin/uname: Permission denied  a:82:{s:9:"nb_visits";s:6:"Visits";s:16:"nb_uniq_visitors";s:15:" .... Some more text that looks like Piwik stats;}'.

ERROR CoreConsole[2015-03-19 14:22:23] The Piwik URL http://domain.name/piwik/index.php does not seem to be pointing to a Piwik server. Response was 'sh: /bin/uname: Permission denied  a:82:{s:9:"nb_visits";s:6:"Visits";s:16:"nb_uniq_visitors";s:15:" .... Some more text that looks like Piwik stats;}'.

[Exception]

The Piwik URL http://domain.name/piwik/index.php does not seem to be pointing to a Piwik server. Response was 'sh: /bin/uname: Permission denied a:82:{s:9:"nb_visits";s:6:"Visits";s:16:"nb_uniq_visitors";s:15:" .... Some more text that looks like Piwik stats;}'.

core:archive [--url="..."] [--force-all-websites] [--force-all-periods[="..."]] [--force-timeout-for-periods[="..."]] [--skip-idsites[="..."]] [--force-idsites[="..."]] [--force-periods[="..."]] [--force-date-last-n="..."] [--force-date-range[="..."]] [--concurrent-requests-per-website[="..."]] [--disable-scheduled-tasks] [--accept-invalid-ssl-certificate] [--xhprof]

Hi there

can you please apply this patch: Hide error message in case binary is not readable by mattab · Pull Request #7487 · matomo-org/piwik · GitHub

and confirm whether this fixes the issue?

Also add --accept-invalid-ssl-certificate to your command:


#!/bin/bash

php /home/piwik/console core:archive --accept-invalid-ssl-certificate --url=http://domain.name/piwik/ > /home/piwik/piwik-archive-output.log

I have implemented the patch:


private static function isSystemNotSupported()
    {
        #$uname = @shell_exec('uname -a');
        $uname = @shell_exec('uname -a 2> /dev/null');

        if (empty($uname)) {
            $uname = php_uname();
        }

        if (strpos($uname, 'synology') !== false) {
            return true;
        }
        return false;
    }

Tried executing again, with and without --accept-invalid-ssl-certificate as Matthieu Napoli suggested - the result is the same in both cases:


ERROR CoreConsole[2015-03-20 11:05:05] Got invalid response from API request: http://domain.name/piwik/index.php?module=API&method=API.get&idSite=1&period=week&date=last260&format=php&token_auth=removed&trigger=archivephp. Response was ' Fatal error: Out of memory (allocated 28311552) (tried to allocate 4104 bytes) in /home/piwik/core/DataTable.php on line 1156 '

ERROR CoreConsole[2015-03-20 11:05:08] Got invalid response from API request: http://domain.name/piwik/index.php?module=API&method=API.get&idSite=1&period=month&date=last52&format=php&token_auth=removed&trigger=archivephp. Response was 'aOut of memory (Needed 8164 bytes) a:2:{s:6:"result";s:5:"error";s:7:"message";s:67:"SQLSTATE[HY000]: General error: 2008 MySQL client ran out of memory";}'

ERROR CoreConsole[2015-03-20 11:05:10] Got invalid response from API request: http://domain.name/piwik/index.php?module=API&method=API.get&idSite=1&period=year&date=last7&format=php&token_auth=removed&trigger=archivephp. Response was 'aOut of memory (Needed 24492 bytes) a:2:{s:6:"result";s:5:"error";s:7:"message";s:67:"SQLSTATE[HY000]: General error: 2008 MySQL client ran out of memory";}'

ERROR CoreConsole[2015-03-20 11:05:11] 3 total errors during this script execution, please investigate and try and fix these errors.
ERROR CoreConsole[2015-03-20 11:05:11] 3 total errors during this script execution, please investigate and try and fix these errors.


  [Exception]                                                                                    
  3 total errors during this script execution, please investigate and try and fix these errors.

Hi there,

the message is not the same, now it says:

Fatal error: Out of memory

and

aOut of memory (Needed 24492 bytes) a:2:{s:6:“result”;s:5:“error”;s:7:“message”;s:67:“SQLSTATE[HY000]: General error: 2008 MySQL client ran out of memory”;

please increase the memory for your mysql server and php configuration

I will try but it might be so that I’m not able to modify these memory settings. Is there a way to make the archiving work with less resources?

You will need to make your site have less traffic then :wink: (just kidding)

The (soon-to-be-released) Piwik 2.12.0 comes with a few memory improvements maybe it will help but there’s no guarantee at all. You most likely need to allow more RAM usage.

Unfortunately I’m not allowed any more RAM (shared hosting), but the site in question is getting only ~7000 visitors a month. I have another with a lot more traffic, running an older version of Piwik that works OK. It doesn’t make sense to me that an older version of Piwik on a site with 10 times the traffic would require less resources (same shared hosting). I will wait for the new version then.

Also of note is that the I have selected the option “Allow Piwik archiving to trigger when reports are viewed from the browser” and archiving through that option works fine without any errors at all. So why would this work fine and the console archiving not work?

Also of note is that the I have selected the option “Allow Piwik archiving to trigger when reports are viewed from the browser” and archiving through that option works fine without any errors at all. So why would this work fine and the console archiving not work?

Because there is a different PHP configuration depending on your web server or when you call it via cron / CLI.
I think your PHP CLI configuration does not have enough memory

I’ve increased my memory limit to 250MB and it seems to work now, although it does seem to take more time than the 2.2.0 version.

Would it take significantly more memory for the site that has 10x more traffic or would it use about the same amount of memory?

250MB is quite low. That explains the previous error if it was even lower. I think for more traffic you might need a little more (but it always depends what “more traffic” means).

Like 100k visitors with about 400k impressions per month?

with such traffic I would recommend setting 1G of memory