Skip to content

Fix behavior keepalive#4904

Closed
maxvalentini77 wants to merge 7 commits intojoomla:stagingfrom
maxvalentini77:fix-behavior-keepalive
Closed

Fix behavior keepalive#4904
maxvalentini77 wants to merge 7 commits intojoomla:stagingfrom
maxvalentini77:fix-behavior-keepalive

Conversation

@maxvalentini77
Copy link
Copy Markdown
Contributor

I found three issues:

1: In some cases, call an invalid URL, resulting in a response with code 404. (still refresh the session)
2: Update the article hits counter.
3: Work in different ways with "Search Engine Friendly URLs" enabled or disabled.

How to reproduce number 1

  • Enable "Search Engine Friendly URLs"
  • Set "Session Lifetime" to 1 (not required but useful to test faster!)
  • Create a menu of type "Menu Heading" and call it "heading"
  • Create a menu that point to an article and add it as child of "heading"
  • Create a Login module and put it some where in the page (add the "behavior.keepalive")
  • Use the article menu (you will be redirected to a page with an URL like "www.host.net/index.php/heading/article")
  • Wait some "Session Lifetime" minutes and an ajax call to the URL "www.host.net/index.php/heading/" will be executed but ends with a 404 error

The session is refreshed but it isn't nice to generate a 404 error that, for example, ends up in the apache logs.

How to reproduce number 2

  • Set "Session Lifetime" to 1 (not required but useful to test faster!)
  • Create a menu that point to an article and set it as default
  • Create a Login module and put it some where in the page (add the "behavior.keepalive")
  • Go to the homepage of the site, the article will be displayed with a counter hits = C
  • Wait some "Session Lifetime" minutes and an ajax call to the homepage will be executed (increasing the hits counter)
  • Refresh the page

The counter was increased by 1+X where X is the number of ajax calls.

How to reproduce number 3

  • Disable "Search Engine Friendly URLs"
  • Set "Session Lifetime" to 1 (not required but useful to test faster!)
  • Create a menu of type "Menu Heading" and call it "heading"
  • Create a menu that point to an article and add it as child of "heading"
  • Create a Login module and put it some where in the page (add the "behavior.keepalive")
  • Use the article menu (you will be redirected to a page with an URL like "www.host.net/index.php?option=com_content&view=article&id=12&Itemid=160")
  • Wait some "Session Lifetime" minutes and an ajax call to the URL "www.host.net/" will be executed.

This is the same procedure to reproduce number 1 but ends with a different behavior that, if the homepage display an article, generate the same issue of number 2.
(This because the homepage of the site has been called.)

Proposed solution

I modified the URL of the ajax call from "./" to:

JRoute::_("index.php?option=com_ajax&format=json", false)

This call refresh the session without generate any html and/or call model methods that can lead to unexpected/unwanted behaviors (for example in an increased article hits counter).
This call is available on both site and administrator applications.

To test it in the administrator application (for example) go to the edit category page that include the "behavior.keepalive" and wait for the ajax call.

@Fedik
Copy link
Copy Markdown
Member

Fedik commented Apr 10, 2015

thanks @maxvalentini77
I had similar idea, and found this is already suggested couple months ago 😄

couple note:
you do not need to call JRoute as it useless here, enough:
JUri::base(true) . 'index.php?option=com_ajax&format=json';

and can you please make $refreshTime fixed, example 1 minute , so we could solve also that issue #6730

something like:

JFactory::getDocument()->addScriptDeclaration('
!window.setInterval(function(){
var r; try{ r = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP")}catch(e){};if(r){r.open("GET","'.$url.'",true);r.send(null)}
}, 60000);
');

@maxvalentini77
Copy link
Copy Markdown
Contributor Author

Hi @Fedik
I made the changes.

Thank you

@Fedik
Copy link
Copy Markdown
Member

Fedik commented Apr 10, 2015

I am sorry, I missed slash in my example, for url:
JUri::base(true) . '/index.php?option=com_ajax&format=json';

and thanks for this, I try test tomorrow

@maxvalentini77
Copy link
Copy Markdown
Contributor Author

Added the slash and tested, seems to work well.
Time is now fixed to 60 seconds, I don't know if also solves the #6730.

@Fedik
Copy link
Copy Markdown
Member

Fedik commented Apr 11, 2015

test works for me good, also fix #6730 issue for me
thanks!

@Fedik
Copy link
Copy Markdown
Member

Fedik commented Apr 14, 2015

test
still works good 😄

@Fedik
Copy link
Copy Markdown
Member

Fedik commented May 13, 2015

it is ready to "RTC" or? 😃


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/4904.

@demis-palma
Copy link
Copy Markdown
Contributor

@test successful
@Fedik I guess that your test has not been notified because it lacks the (at) symbol.

@Fedik
Copy link
Copy Markdown
Member

Fedik commented May 13, 2015

the (at) symbol useless here 😉
people use it as quick way to make "test" word bold 😄

@zero-24
Copy link
Copy Markdown
Contributor

zero-24 commented May 13, 2015

Thanks for the bump and the tests @Fedik and @demis-palma

RTC'ing now!


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/4904.

@zero-24 zero-24 added the RTC This Pull Request is Ready To Commit label May 13, 2015
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn’t we repeat the call every X seconds? Where X is the option set in global config. So all I am saying is: restore this line here $script .= '},' . $refreshTime . ');'; and a few lines above $lifetime = ($config->get('lifetime') * 60000);

Right now this is fixed to a call per minute, which for some busy sites will create more load...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the begging i don't change the time, but @Fedik open the issue #6730 and ask to me to reduce the time to 1 minute to fix also the #6730.
With this change the request is very "light" do not generate any html reducing time and size of the request (without this change can request the homepage!).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxvalentini77 I wasn’t aware of #6730

With 60000 not always refresh the session if the session lifetime is set to 1 minute. Now work always well even with this very small value.
@maxvalentini77
Copy link
Copy Markdown
Contributor Author

I notice that the session not always be refreshed if the session lifetime is set to 1 minute.
@Fedik and @demis-palma can check again that continue to works well to you too?
(sorry for the inconveniente)

I also noticed that the session lifetime can be set a zero or negative value in the configuration page.
Zero behavior is equals to default of 15 minutes.
Negative value cause the impossibility to use the application!
(created the issue #6954 for this)

@Fedik
Copy link
Copy Markdown
Member

Fedik commented May 15, 2015

@maxvalentini77 I already use this on my sites, where default session handler is File or APC,
and refresh session each minute works good, if compare with original

session lifetime 1 minute I think have not much sense, not sure that we need to worry about it 😉
but maybe someone has better arguments 😄

@zero-24 zero-24 modified the milestone: Joomla! 3.4.4 Jul 2, 2015
@Kubik-Rubik
Copy link
Copy Markdown
Member

Thank you @maxvalentini77! Merged.

@zero-24 zero-24 removed the RTC This Pull Request is Ready To Commit label Oct 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants