Cache and article hits issue

Discussion regarding Joomla! 2.5 Performance issues.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
vbarlakoski
Joomla! Intern
Joomla! Intern
Posts: 64
Joined: Sun May 02, 2010 9:50 pm

Cache and article hits issue

Postby vbarlakoski » Tue Nov 20, 2012 9:16 pm

Hello!

When i set cache option ON, on my joomla site, the article HITS stop counting at all.

How can i use cache properly but not affecting the counting function?

Thanks!

vidak
Joomla! Apprentice
Joomla! Apprentice
Posts: 45
Joined: Mon Mar 30, 2009 9:43 pm
Contact:

Re: Cache and article hits issue

Postby vidak » Fri Nov 23, 2012 12:44 am

Counting function is bad and doesn't give you proper information.
Use Google Analytic. It is about 98% right.

vbarlakoski
Joomla! Intern
Joomla! Intern
Posts: 64
Joined: Sun May 02, 2010 9:50 pm

Re: Cache and article hits issue

Postby vbarlakoski » Fri Nov 23, 2012 8:46 am

That's kind of bad solution for this :)

Thanks anyway, i will wait for actual solution.

User avatar
kenmcd
Joomla! Champion
Joomla! Champion
Posts: 5672
Joined: Thu Aug 18, 2005 2:09 am
Location: California
Contact:

Re: Cache and article hits issue

Postby kenmcd » Fri Nov 23, 2012 5:33 pm

vbarlakoski wrote:When i set cache option ON, on my joomla site, the article HITS stop counting at all.
How can i use cache properly but not affecting the counting function?

EDITED

The full page cache affects anything which has regular updates.
Which is why the full page cache can often have limited usefulness.

.
Last edited by kenmcd on Fri Nov 23, 2012 6:29 pm, edited 1 time in total.
██ LibreTraining

vbarlakoski
Joomla! Intern
Joomla! Intern
Posts: 64
Joined: Sun May 02, 2010 9:50 pm

Re: Cache and article hits issue

Postby vbarlakoski » Fri Nov 23, 2012 5:55 pm

So, Conservative cache caches just display or full page cache, because when cache expires, hits are not updated at all!

User avatar
kenmcd
Joomla! Champion
Joomla! Champion
Posts: 5672
Joined: Thu Aug 18, 2005 2:09 am
Location: California
Contact:

Re: Cache and article hits issue

Postby kenmcd » Fri Nov 23, 2012 6:32 pm

.
What I previously posted above was incorrect (so I edited it).

Hits are not counted in the background when the full page is cached.
Joomla counts hits when the page is built, and since it is not being built, no counting.

The best solution is to use external analytics as suggested above.

.
██ LibreTraining

vbarlakoski
Joomla! Intern
Joomla! Intern
Posts: 64
Joined: Sun May 02, 2010 9:50 pm

Re: Cache and article hits issue

Postby vbarlakoski » Fri Nov 23, 2012 6:39 pm

I have found third-party plugin CacheControl, and i forbid option=com_content&view=article to cache, so, i have my hits back.

Joomla developers should really look into this thing.

Thanks for help!

User avatar
kenmcd
Joomla! Champion
Joomla! Champion
Posts: 5672
Joined: Thu Aug 18, 2005 2:09 am
Location: California
Contact:

Re: Cache and article hits issue

Postby kenmcd » Fri Nov 23, 2012 7:34 pm

.
Then you have basically disabled caching for all content.
That makes no sense to me.
Just turn the cache plug-in Off instead.


.
██ LibreTraining

vbarlakoski
Joomla! Intern
Joomla! Intern
Posts: 64
Joined: Sun May 02, 2010 9:50 pm

Re: Cache and article hits issue

Postby vbarlakoski » Fri Nov 23, 2012 7:39 pm

Its off for Article View from com_content, not for blog view, not for featured view, not for modules outside that view, not for other components. How this does not make sense?

masoksian
Joomla! Apprentice
Joomla! Apprentice
Posts: 11
Joined: Sun Jun 22, 2008 8:28 pm

Re: Cache and article hits issue

Postby masoksian » Mon Nov 26, 2012 1:11 pm

same problem

system: Joomla 2.5.8

if cache enabled article hits stopping. :((

User avatar
SimonHayter
Joomla! Guru
Joomla! Guru
Posts: 530
Joined: Tue Nov 29, 2011 2:43 pm
Location: Bournemouth
Contact:

Re: Cache and article hits issue

Postby SimonHayter » Mon Nov 26, 2012 5:58 pm

To be honest, the hits counter within Joomla is pretty naff. Most opt to use external applications to monitor success of pages in a much detailed way than just 1 hit, 2 hits, and so on.

vbarlakoski
Joomla! Intern
Joomla! Intern
Posts: 64
Joined: Sun May 02, 2010 9:50 pm

Re: Cache and article hits issue

Postby vbarlakoski » Wed Dec 05, 2012 11:09 am

Is there any way in template_name/html/com_content/article/default.php to make connection with the database and increase the hits count? In that way, that query wont be cached i think or i'm wrong?

It seems wrong that cache stops hits counting, because there is ordering by hits option.

User avatar
bradm
Joomla! Explorer
Joomla! Explorer
Posts: 369
Joined: Tue Apr 19, 2011 1:58 pm
Location: Virginia Beach, Va
Contact:

Re: Cache and article hits issue

Postby bradm » Fri Feb 21, 2014 4:00 pm

I know this is an older post, but I was able to come up with a solution for my website, increasing hits even if a cached page is being served. I posted the basic concept of the solution here: http://joomlacode.org/gf/project/joomla ... m_id=29831

It does involve a change to the core, but it works, and that's what I needed. If anyone has any questions as to how to get this working, just let me know.
Please let me know if I can help any further.
Thanks, BradM, with http://www.inmotionhosting.com Support

itoctopus
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3182
Joined: Mon Nov 25, 2013 4:35 pm
Location: Montreal, Canada
Contact:

Re: Cache and article hits issue

Postby itoctopus » Sat Mar 01, 2014 5:31 am

Another way that doesn't involve modifying the core, is to create a system plugin that is run after the cache plugin runs, and that system plugin will update the page count. This'll work and it doesn't involve changing the core.
http://www.itoctopus.com - Joomla consulting at its finest
https://twitter.com/itoctopus - Follow us on Twitter

vbarlakoski
Joomla! Intern
Joomla! Intern
Posts: 64
Joined: Sun May 02, 2010 9:50 pm

Re: Cache and article hits issue

Postby vbarlakoski » Sat Mar 01, 2014 11:26 am

There is a hack that works with Conservative and Progressive cache but not with System Cache.

In Site ROOT/index.php after $app->route(); insert this code:

Code: Select all

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

 $db->query();
}


This will update hits in database in real time, but in article view will update every time when cache session expires with actual database hits.

User avatar
bradm
Joomla! Explorer
Joomla! Explorer
Posts: 369
Joined: Tue Apr 19, 2011 1:58 pm
Location: Virginia Beach, Va
Contact:

Re: Cache and article hits issue

Postby bradm » Mon Mar 03, 2014 5:22 pm

Hi @itoctopus and @vbarlakoski,

Great ideas! Were you able to prevent Joomla from updating the hits two times in the event someone was not seeing a cached version of the page? IE, the code / plugins you described would update the hits, and then the normal Joomla code would run and update the hit again.
Please let me know if I can help any further.
Thanks, BradM, with http://www.inmotionhosting.com Support

vbarlakoski
Joomla! Intern
Joomla! Intern
Posts: 64
Joined: Sun May 02, 2010 9:50 pm

Re: Cache and article hits issue

Postby vbarlakoski » Mon Mar 03, 2014 5:25 pm

Joomla code will run once to activate new cache. So it will update hit once. I think its better to have one time double hit every time cache expires, than have no hits at all while cache is active.

But, this is temporary fix, it should not be permanent one if you need to edit the core.

I hope that Joomla will adapt the system to work properly with or without cache. Hits must be excluded from caching.

pankajsharma21+
Joomla! Apprentice
Joomla! Apprentice
Posts: 30
Joined: Fri Feb 14, 2014 8:59 am

Re: Cache and article hits issue

Postby pankajsharma21+ » Mon Apr 28, 2014 7:53 am

HI
everyone
i tried the solution by @vbarlakoski
but the problem is still there ,
As i tested it for joomla 3.2.2 the article hit counter call is different in both cases(joomla3.2.2 and joomla2.5.x)

in joomla 3.2.2 the article hit counter is increased by

Code: Select all

   public function hit($pk = 0)
   {
      $input = JFactory::getApplication()->input;
      $hitcount = $input->getInt('hitcount', 1);

      if ($hitcount)
      {
         $pk = (!empty($pk)) ? $pk : (int) $this->getState('article.id');
         $db = $this->getDbo();

         $db->setQuery(

            'UPDATE #__content' .
               ' SET hits = hits + 1' .
               ' WHERE id = ' . (int) $pk
         );

         try
         {
            $db->execute();
         }
         catch (RuntimeException $e)
         {
            $this->setError($e->getMessage());
            return false;
         }
      }
      return true;
   }




this code


I tried it to add in the root/index.php file but its not working for me , may be the issue is incorrect implementation of the above code .
is there anyone who will help me to solve this known joomla bug?
Regards

vbarlakoski
Joomla! Intern
Joomla! Intern
Posts: 64
Joined: Sun May 02, 2010 9:50 pm

Re: Cache and article hits issue

Postby vbarlakoski » Mon Apr 28, 2014 8:02 am

I have done it this way:

I`m using jotCache for page caching.

Then i have created module that runs code for article hits increase.

Code: Select all

<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

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

?>


Then I have excluded the module from JotCache caching.

This works perfectly in 2.5.

pankajsharma21+
Joomla! Apprentice
Joomla! Apprentice
Posts: 30
Joined: Fri Feb 14, 2014 8:59 am

Re: Cache and article hits issue

Postby pankajsharma21+ » Mon Apr 28, 2014 8:14 am

HI @vbarlakoski
is it custom html module ??
any idea for joomla3.2.2?

vbarlakoski
Joomla! Intern
Joomla! Intern
Posts: 64
Joined: Sun May 02, 2010 9:50 pm

Re: Cache and article hits issue

Postby vbarlakoski » Mon Apr 28, 2014 8:19 am

You should try it.. Its custom module, that is changing the db values, so it should work in 3 too. Please share the result if you try it.

k2bmedia
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Thu Nov 20, 2008 12:49 pm

Re: Cache and article hits issue

Postby k2bmedia » Wed May 21, 2014 2:09 pm

Does it also work with K2 Items?

pankajsharma21+
Joomla! Apprentice
Joomla! Apprentice
Posts: 30
Joined: Fri Feb 14, 2014 8:59 am

Re: Cache and article hits issue

Postby pankajsharma21+ » Sat Jun 28, 2014 4:11 am

Hi the issue is solved .

kartov
Joomla! Apprentice
Joomla! Apprentice
Posts: 34
Joined: Mon Aug 24, 2015 5:20 pm

Re: Cache and article hits issue

Postby kartov » Fri Mar 11, 2016 12:33 pm

vbarlakoski wrote: ' WHERE id = '.(int) $articleId


All of you be aware that this is SQJ Injection and this brings certain security risks. Did you ever heard about sanitizing inputs?


Return to “Performance - Joomla! 2.5”

Who is online

Users browsing this forum: No registered users and 2 guests