Archive.php: Got invalid response from API request (The response was empty)

Version 2.2.0
Same problem!

And please update How to Set up Auto-Archiving of Your Reports - Analytics Platform - Matomo

Hi,

I’m facing to that 2 errors when I’m trying to update Piwik with archive.php.
My problem is that my website is on a shared hosting and I can’t manage cron as I would like.

INFO ERROR: Got invalid response from API request: http://your-server.org/path/to/piwik/index.php?module=API&method=API.getDefaultMetricTranslations&format=original&serialize=1&trigger=archivephp. Response was ‘
Warning: Unexpected character in input: ‘’ (ASCII=92) state=1 in http://your-server.org/path/to/piwik/console on line 20

Parse error: syntax error, unexpected T_STRING in http://your-server.org/path/to/piwik/console on line 20

INFO Piwik\CronArchiveFatalException ERROR: The Piwik URL http://your-server.org/path/to/piwik/index.php does not seem to be pointing to a Piwik server. Response was ‘’.

Hope someone can help me, I encounter this problem since 2.1.0 update of Piwik, the same with 2.2.0.

Thanks in advance.

I thought, it was the memory-limit, but setting it higher did not work. But now I saw this threat… so it’s not my webhost.

Any idea how to downgrade back to 2.1.0 or the version before 2.2.0? Or will the bug be corrected soon?
Thanks!

I would also like to know if there is a way to revert back to 2.1.0 or if anyone can suggest a “workaround” to this issue?

For me it seems to occur when the site is set to a timezone different than the server’s.

My workaround:

Add


date_default_timezone_set("UTC");

After <?php
in ./console file and than use this cronjob


php /ypur/path/to/piwik/console core:archive --url=https://yoururltopiwik --accept-invalid-ssl-certificate

Works like a charm for me.

Does not work for me. After adding the timezone the same error occurs. The only “solution” is to activate “start archiving on viewing reports in browser”. Any other solution?

Could you specify exactly which file that is?

There is a folder:


\piwik\vendor\symfony\console\Symfony\Component\Console\

with many files, some of which have “console” as part of their names.

And then there are these files:


\piwik\core\DataTable\Renderer\Console.php
\piwik\core\Console.php

Then, there is this one, which also seems part of some console structure:


\piwik\plugins\CoreConsole\Commands\CoreArchiver.php

OK. I found the console file - it’s probably created after installation as it’s not inside the zip file I’ve downloaded.

Anyways - I only have crontab inside my shared hosting’s control panel and it would not allow for something like that to be used:


php /ypur/path/to/piwik/console core:archive --url=https://yoururltopiwik --accept-invalid-ssl-certificate

Maybe there is a different way to set this?

Also, I’m currently using piwik/misc/cron/archive.sh for the cron job?

Well, i’m not a piwik expert. Just using it for a couple of month an run into problems since few weeks as most of you here.
If my workaround doesn’t help i don’t have another solution.

@notify
You can try create a own bash script anywhere beside archive.sh and than just put something like this


#!/bin/sh
php /ypur/path/to/piwik/console core:archive --url=https://yoururltopiwik --accept-invalid-ssl-certificate

in it and add the to your cronjob instead of the “archive.sh”.

I just found out my real source of the problem: piwik/index.php had only Windows authentication enabled. We’re using a custom single-sign-on mechanism in Piwik with IIS. In Piwik 1.x, the archive powershell script worked fine with Windows authentication.

Anyways, I find the error message really misleading. Just found out from the IIS logs that the requests from CLI got a 401 response.

I’m executing archiving in cron job:

5 * * * * www-data /usr/bin/php5 /var/wwwc/piwik/misc/cron/archive.php --url=h t t p : / /www.xxx.yy/piwik/ > /var/log/piwik/piwik-archive.log

I get this error on site 11, which never gave problem (I introduced extra spaces in order to avoid spam check):

One solutions seems to use the command line but this isn’t a solution for me because. I have to use the web cron over http.

Are there any workarounds?

Thanks for your help.

No solution since 1 month. Before version 2.1 all works fine.

@Admin
When you want to solve the problem finally?
With better error messages we could better help the developers!

Why did they change this? In the past web cron worked fine…

…for the use of the command line I have to change my hosting. No way!

I have the same problem in v2.2.0 (CentOS 6.5): Neither archive.php work, nor “console core:archive”. Console does not even output help:


# php /var/webs/wwwpiwik/www/console core:archive --help 
PHP Fatal error:  Allowed memory size of 262144 bytes exhausted (tried to allocate 523800 bytes) in Unknown on line 0
Could not startup.

# php /var/webs/wwwpiwik/www/console core:archive --url=http://wstat1.noa.gr --accept-invalid-ssl-certificate >> /var/webs/wwwpiwik/www/archive-log/piwik-archive1.log
PHP Fatal error:  Allowed memory size of 262144 bytes exhausted (tried to allocate 523800 bytes) in Unknown on line 0

[Note: It is not a problem of memory size; the above error message is standard/generic, when there are all sorts of problems and it doesn’t help debugging.]

Reports generation works from the piwik webpage (visiting Dashboard), but the above command (or any cron job based on it), with or without --acept-invalid-ssl-certificate, fails.

Any advice will be appreciated.

Thanks,
Nick

Sorry, I got this! In /etc/php.ini I had “memory_limit=512MB” whereas I should have “memory_limit=512M”. (I found it by googling, thanks to an older forum thread: https://forums.gentoo.org/viewtopic-t-916546-start-0.html.)

Thus, php from CLI would not run.

The problem was apparent only in CLI, because php-fpm (used by the web apps) has its own php settings.

Now the command:


php /var/webs/wwwpiwik/www/console core:archive --url=http://wstat1.noa.gr >> /var/webs/wwwpiwik/www/archive-log/piwik-archive1.log

…runs. I get 16 identical warnings:


PHP Warning:  date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Helsinki' for 'EEST/3.0/DST' instead in /var/webs/wwwpiwik/www/core/Log.php on line 520

and some identical errors:


ERROR: Got invalid response from API request: http://wstat1.noa.gr/index.php?module=API&method=API.get&idSite=1&period=month&date=last28&format=php&token_auth=a0709b20762bae2088c915aa19a461d2&trigger=archivephp. Response was 'PHP Fatal error:  Allowed memory size of 805306368 bytes exhausted (tried to allocate 71 bytes) in /var/webs/wwwpiwik/www/core/DataTable.php on line 1118

Please advise on the best way to resolve the above!

For the time being I use the trick mentioned above (‘date_default_timezone_set(“UTC”);’ in console script) and it indeed eliminates the aforementioned errors.

All the best,
Nick

@Nick1200
The error with “date() -> date.timezone” is a misconfigured php.ini.
The value “date.timezone” must be set in the php.ini (default it’s not set) or in PHP directly before any date function is used (date_default_timezone_set). If not than you get the PHP Warning that you’ve described.
I’ve the following in my php.ini


[Date]
date.timezone = "Europe/Berlin"

If you cannot set this on your host, you should contact your hoster, this is simple a thing that need to be done.
Doc: PHP: Runtime Configuration - Manual and PHP: List of Supported Timezones - Manual and PHP: date_default_timezone_set - Manual

The other error “Allowed memory size of xxx exchaused” can also be fixed with “memory_limit” in php.ini, or with “ini_set(‘memory_limit’, ‘32M’);”) in PHP code.
For large pages i recommend 1G or higher.
I use 512M for 20.000 pageviews per day.
Doc: PHP: Description of core php.ini directives - Manual

Thanks,

I confirmed that by placing:


date.timezone = "Europe/Athens"

in php.ini no warnings or errors occur. I clarify that the second error also does not occur if date.timezone is set (i.e. no memory_limit adjustment was needed - I use 1024M for 50000 dailly pageviews).

Yet, since the default setting in php.ini for date.timezone is blank, I think that the piwik “console core:archive” script should be able to handle correctly the cases where date.timezone is not set, so that no errors occur.

Best regards,
Nick

Thanks all of you for your feedback here! There was indeed a BUG in piwik as we forgot to set the default timezone in the console. This was a bug nobody reported during the beta/RC testing period so it went live.

I’ve fixed it here: Setting the default timezone to UTC in the core:archive script, refs … · matomo-org/matomo@22e8a7a · GitHub

Hopefully that will solve some of your issues. Please report in a new forum thread if you still have problem after applying this patch. Cheers

Еrror persists :frowning: