Keyword

Caching and hit counter

  • Uzi
  • Uzi's Avatar Topic Author
  • Offline
  • Premium Member
More
6 years 2 days ago - 6 years 2 days ago #170399 by Uzi
Caching and hit counter was created by Uzi
Hi all,

I have a website which I enabled the cache module to speed things up a bit. Which works wonders, but the only thing that bothers me is that the hit counter is not working properly anymore.

I use Conservative caching - Gzip and Jotcache.

I can imagine other people use the cache as well, and use the hit counter as well, so is there a solution to this?

EDIT:

Ok so there as a topic here on this forum regarding this issue. They provided me this:
<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

if (isset($_GET['view']) && strtolower($_GET['view']) == 'item') {
 $articleId = (int) $_GET['id'];
 
 $db = JFactory::getDBO();
 $db->setQuery(
                        'UPDATE #__k2_items' .
                        ' SET hits = hits + 1' .
                        ' WHERE id = '.(int) $articleId
                );
 $db->query();
}

?>

To put this in the K2 Tools module and parse the PHP code. Unfortunately this does not work when caching is enabled. It seems to me that the actual code does not gets fired because the hits are not added. Also when I disable caching alltogether and refresh the page the hits should be doubled (the normal hit counter + this module) but unfortunately again, this does not happen. I think there is something wrong with this code. Could someone help me out?
Last edit: 6 years 2 days ago by Uzi.

Please Log in or Create an account to join the conversation.

  • Uzi
  • Uzi's Avatar Topic Author
  • Offline
  • Premium Member
More
6 years 2 days ago #170401 by Uzi
Replied by Uzi on topic Caching and hit counter
Found the solution:
<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

if (isset($_GET['view']) && strtolower($_GET['view']) == 'item') {
 $articleId = JRequest::getInt('id');
 $db = JFactory::getDBO();
 $db->setQuery(
                        'UPDATE #__k2_items' .
                        ' SET hits = hits + 1' .
                        ' WHERE id = '.(int) $articleId
                );
 $db->query();
}

?>

The article getting was not properly in the code. I changed that to above:
$articleId = JRequest::getInt('id');

This works!

Only jotcache gives problems because it also caches modules, so I need to figure that out, but with Native joomla caching + exluding the modules you don't want cached, this works.

Please Log in or Create an account to join the conversation.

More
6 years 1 day ago #170411 by JoomlaWorks
Replied by JoomlaWorks on topic Caching and hit counter
This is something that will surely be addressed in K2 in 2019. The right way is actually to do this using JS so you can have real-time hit counting, bypassing CDN, server-side caching (Varnish/Nginx in proxy mode), Joomla's caching, browser (client-side) caching etc.

So basicallythe process is to load a JS file with a client-side generated timestamp (to bypass any caching, server or client side) on the "item" view in K2 only and then send an async/delayed POST request to trigger an extra hit in the database for that item. Now since that process may cause load on popular sites (sites with more than 100,00 monthly visitors or a few million pageviews per month), the plan is to move the "hits" records to a separate table so writing to that table is blazing fast.

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • Павел Абакумов
  • Павел Абакумов's Avatar
  • Offline
  • New Member
More
4 years 9 months ago #174607 by Павел Абакумов
Replied by Павел Абакумов on topic Caching and hit counter
It would be very nice if the developers would make a counter that would work in real-time caching.

Please Log in or Create an account to join the conversation.

More
4 years 9 months ago #174608 by JoomlaWorks
Replied by JoomlaWorks on topic Caching and hit counter
That's the plan ;)

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • Павел Абакумов
  • Павел Абакумов's Avatar
  • Offline
  • New Member
More
4 years 9 months ago #174609 by Павел Абакумов
Replied by Павел Абакумов on topic Caching and hit counter
Is it possible to realize this faster for a donation?

Please Log in or Create an account to join the conversation.

More
4 years 9 months ago #174610 by JoomlaWorks
Replied by JoomlaWorks on topic Caching and hit counter
Not at the moment because there's a specific development time schedule.

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum