New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
renderer format is not valid - fatal php error after 2.14.0 #8365
Comments
This is the PHP API call in WP-Piwik:
This is the constants definition:
If I add the workaround lines, the initial error changes to "renderer format not valid"... it does not care which renderer format I use (tested with PHP and JSON). Hope this helps :-( |
Can you maybe try to do a manual update see http://piwik.org/docs/update/#the-manual-three-step-update ? Maybe some files are missing somehow. It should work otherwise. I had a rough look through the code. If replacing some files doesn't work maybe you can provide us the content of the whole file you're using (not sure if the one above is everything within the file) and an example URL request. Then we can try to reproduce and debug |
i have already performed a manual update - so that is not the issue here. |
A manual update did not solve the issue. Demo code 1 (using my real auth token & path, of course):
This causes:
If I add the "environment workaround" like this...
... the test script works as expected. But in WP-Piwik itself it still does not work. By adding these Environment-lines, it just switches to
I will try to figure out the difference between my WP-Piwik code and the one shown above (all lines above are copied and pasted from my WP-Piwik code, but changed to work standalone, of course). If I figure out something new, I will tell you asap. (Updating manually did not change anything.) |
Ok, now I got it: If the environment init is performed a second time, the renderer error appears. Try this code:
The first request will perform as expected, the second one will throw the exception. Of course, I can prevent my code to call the workaround twice... but there are two questions left:
|
@diosmosis do you maybe know this?
Using At the same time it is needed to do bootstrap Piwik as shown in our internal API call example code: https://github.com/piwik/piwik/blob/2.14.1-rc1/misc/others/api_internal_call.php#L16 @diosmosis Should we mark this class as API? Is it stable? Can be maybe find a way where it is not needed to create an environment? I'm not into this part so if not that's okay |
Re @braekling
You can use a try-catch w/ StaticContainer::getContainer(). It is, however, a better idea to store a single environment instance instead of recreating it each time you need to issue a local API request. The Environment should be created & initialized once per HTTP request that is sent to the app that is accessing Piwik locally.
For BC, you can separate the FrontController & Environment initialization, eg:
Re @tsteur
The environment encapsulates the Piwik environment setup, so it's always needed (just as FrontController::init() or the random tracker functions were needed before). Regarding API, it's mostly stable, but it likely doesn't need to be made API (though PiwikPRO will use it). Ideally, there would be none of this and just a WebApplication class, and "local requests" would be made like this:
However, I couldn't get that done within one release. |
Sweet, was just wondering whether it could be done on
FYI: A while ago I created this issue: #7268 but that's for talking to the external API. I forgot why one would use the internal API at all and not connect to the external API. There shouldn't be a huge speed difference but I can imagine it's good if one eg doesn't want to have the |
Just FYI, FrontController::init() will be removed eventually, in favor of application encapsulation. (I guess this is what you meant by "FrontController shouldn't care about environment init"?).
In general I think sending actual web requests seems a better idea to me than loading Piwik's PHP files to access an instance. |
Yep @braekling I wonder if it was possible to achieve the same by calling the external HTTP API see eg http://developer.piwik.org/api-reference/reporting-api ? |
Ok, thank you both. I will check if the environment class exists and store the instance in a static variable (I'm calling the API in a class context) - so I can check if the environment is already initialized. This should work for all Piwik versions. :-) @tsteur WP-Piwik offers the users to choose between HTTP and PHP Reporting API. Some users are not able or don't want to connect to Piwik using the HTTP API for several reasons, e.g., because of mod_security restrictions. But as described before, it should work this way. |
makes sense. Can we close this issue in this case? Please let me know if not and I reopen |
From my side this is solved - thanks! But I don't know if this also works for @propertunist ... ? |
i am only calling one API call per page, so from what i have understood, i don't need to use a static variable for the environment.
did i miss something else? |
Environment's constructor requires a parameter, maybe just adding
|
oh, my mistake - the code i pasted was not the actual code i am using - i copied it from the thread here. |
@propertunist Can you add an echo to the script before |
yes, it is being run twice. i did identify that and point it out in my original ticket - but don't know enough about the design of piwik to explain why or what to do. |
Piwik shouldn't be the cause of it running twice, Piwik won't execute the script that accesses Piwik, only your website will. Can you print out a stack trace immediately after the enviornment is initialized? eg, If you don't want to do this, however, you can, as stated above use a try-catch w/ StaticContainer::getContainer(), and only init an environment if it throws. |
aha, i just found that the cause is that i am calling the piwik function twice per page (i forgot i put the other call in there). i have added a static variable to my function and now it all works ok. :) |
as requested, here is the source code for this issue (#8333) that has persisted beyond the recent release of piwik - 2.14.0.
this code includes the workaround that appeared in the forum that i have mentioned several times already. without the workaround, there is a fatal error relating to a container not being available yet (or similar error) and with the workaround, i see a fatal error of this form:
renderer format 'json' not valid. try any of the following instead.
my code here worked fine before the 2.14.0 upgrade.
The text was updated successfully, but these errors were encountered: