Skip to content
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

PHP tracking first page reload is slow #1

Open
NicoHood opened this issue Dec 31, 2020 · 5 comments
Open

PHP tracking first page reload is slow #1

NicoHood opened this issue Dec 31, 2020 · 5 comments
Labels
help wanted Extra attention is needed

Comments

@NicoHood
Copy link
Owner

On a website with not much traffic the first page load in the morning takes a bit longer. Possible reasons:

  • DNS resolution
  • Matomo instance is in idle mode

This does not happen with the plugin disabled. It could be solved with an async task, as the execution of the tracking is not critical. But how to do that properly?

@klamann
Copy link

klamann commented Feb 6, 2022

Hi @NicoHood, I have the same issue with PHP tracking. Had to deactivate the plugin, because it caused frequent downtimes.

I'm not sure why matomo fails to process the request in a reasonable amount of time, but we could at least try to mitigate the issue. My preferred solution would also be an asynchronous request, but I don't know if there's a good way to do this in PHP. Probably with pthreads?

The alternative would be to reduce the request timeout to a reasonably low value so that it won't crash the entire website. So maybe change CURLOPT_TIMEOUT, or rather requestTimeout, to something like 3-5 seconds by default, and make this configurable in the plugin settings? I would prefer certain visists not to be tracked over certain visitors seeing an error page because matomo failed to respond in time.

@NicoHood
Copy link
Owner Author

NicoHood commented Feb 6, 2022

I think this needs to be fixed upstream: matomo-org/matomo-php-tracker#88

I am using the javascript tracking on my site now, which is also available with this plugin.

@yacode11
Copy link

yacode11 commented Apr 27, 2022

Grav does some magic here to provide an onShutdown event that the plugin could hook into. At least for systems that run PHP-FPM it should work fine I think, not sure about FastCGI (they do some crazy stuff like header('Content-Encoding: identity'); which just strikes me as odd because it explicitly should not be used but maybe it works).

Anyway what do you think? Even without any upstream fixes, shouldn't that already solve the problem? If you think so, I can try writing a PR.

@NicoHood
Copy link
Owner Author

That sounds nice, but does it work for you? Have you tested it?

@yacode11
Copy link

Haven't tested implementing this here in this plugin, but I have used fastcgi_finish_request() previously in another project and it worked great for similar use-cases. Biggest downside being that the function is only available when using PHP-FPM. I haven't tested any of the workarounds for FastCGI that Grav is employing.

This technique would obviously be incompatible with JavaScript tracking and it wouldn't be possible to output a blocking reason to JavaScript file anymore. Other than that, I don't think the plugin would need a lot of modification so maybe I'll just make a fork and give it a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants