Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: Major Minor - syyskuu 12, 2013, 03:31:51 IP

Otsikko: Recent Posts Automatic Updater
Kirjoitti: Major Minor - syyskuu 12, 2013, 03:31:51 IP
If you go to: kanyetothe.com/forum/ (created with SMF)

You'll see that they have a "Latest Posts" section in which they show the latest posts within the forum on the right sidebar.  But if you wait a few seconds, you will see that new posts fade in and appear automatically.  So when someone posts something new, the user doesn't have to refresh their browser to see more recent posts, instead the forum updates itself and the newest posts fade in and appear automatically.

I'm assuming there is no modifications available on this website for download that do the same thing, and it was most likely made with custom coding from scratch, right?  With that being said, how would one go about making an automatic recent posts updater that works like the website listed above? Any help / ideas / insight would truly be appreciated!  :)
Otsikko: Re: Recent Posts Automatic Updater
Kirjoitti: All Colours Sam - syyskuu 12, 2013, 03:38:06 IP
Welcome. The annoying captcha goes a way after a few posts.

Is not really a real time thing, more likely a jQuery script that loads an RSS feed, post 5 of those links then waits a few seconds and then shows the rest.

You can do a search for those scripts, just do a search for "rss reader". SMF already provides an RSS feed for latest post IIRC.
Otsikko: Re: Recent Posts Automatic Updater
Kirjoitti: Major Minor - syyskuu 12, 2013, 04:26:37 IP
Lainaus käyttäjältä: Suki - syyskuu 12, 2013, 03:38:06 IP
Welcome. The annoying captcha goes a way after a few posts.

Is not really a real time thing, more likely a jQuery script that loads an RSS feed, post 5 of those links then waits a few seconds and then shows the rest.

You can do a search for those scripts, just do a search for "rss reader". SMF already provides an RSS feed for latest post IIRC.
Thanks for the response! So you are saying that there are downloadable scripts within this website that would achieve the same idea / result as the website I listed, where the newest posts "appear" to be updating by themselves?  I searched "rss reader" and didn't really find anything that appeared to be too helpful... Maybe I'm not looking hard enough  :(
Otsikko: Re: Recent Posts Automatic Updater
Kirjoitti: IchBin™ - syyskuu 12, 2013, 05:36:16 IP
Not likely on this site. In google. Just search for ajax rss feed reader or something to that effect.
Otsikko: Re: Recent Posts Automatic Updater
Kirjoitti: Major Minor - syyskuu 12, 2013, 06:00:57 IP
Thanks guys... correct me if I am wrong but as far as I know, the script isn't literally retrieving the latest posts and then constantly posting new ones... It's just grabbing say 20 posts, but only displaying 10 posts and then the other 10 will fade in and "appear" over time? I'm not sure if that is how it works because the new posts that appear don't appear every say.. 5 seconds, the new posts appear at random times, sometimes even two or three at a time, much like the patterns of actual posts within the forum (sometimes there are 2 or 3 posts within 5 seconds, sometimes it will take 10 seconds for a new post to appear).  If anyone could explain the concept of how this works on their website, that'd be great.  Or maybe I have more reading to do...  :laugh:
Otsikko: Re: Recent Posts Automatic Updater
Kirjoitti: All Colours Sam - syyskuu 12, 2013, 08:21:56 IP
It looks like a custom JavaScript, you can, of course build an ajax call and set it up to be callable every 5 seconds, not to difficult to achieve however it will kill your forum rather quickly since retrieving the latest post isn't s cheap query and calling an expensive query every 5 seconds for every user whos visiting your site is not going to be pretty.

On a closer look, it seems that they are indeed using an ajax event to retrieve the latest post.
Otsikko: Re: Recent Posts Automatic Updater
Kirjoitti: Major Minor - syyskuu 12, 2013, 09:50:37 IP
Lainaus käyttäjältä: Suki - syyskuu 12, 2013, 08:21:56 IP
It looks like a custom JavaScript, you can, of course build an ajax call and set it up to be callable every 5 seconds, not to difficult to achieve however it will kill your forum rather quickly since retrieving the latest post isn't s cheap query and calling an expensive query every 5 seconds for every user whos visiting your site is not going to be pretty.

On a closer look, it seems that they are indeed using an ajax event to retrieve the latest post.
So using custom ajax to do this would kill the forum, but the website I linked uses ajax to do it??  :o

It must be two completely different codes / concepts, right?
Otsikko: Re: Recent Posts Automatic Updater
Kirjoitti: emanuele - syyskuu 13, 2013, 05:13:15 AP
It *may*, everything is always relative.
It depends on the number of posts, on the activity on the forum, on the server.
Otsikko: Re: Recent Posts Automatic Updater
Kirjoitti: Major Minor - syyskuu 13, 2013, 01:56:14 IP
Lainaus käyttäjältä: emanuele - syyskuu 13, 2013, 05:13:15 AP
It *may*, everything is always relative.
It depends on the number of posts, on the activity on the forum, on the server.
posts within that forum are literally being posted every 2 seconds.. don't know if that helps at all but it should definitely give you a rough idea towards how active the forum is  :) one thing i also noticed is that the latest posts on the sidebar will only update for about 20 seconds, or 10 posts or so (sometimes less, sometimes more) and then it will stop updating... and also the odd time u go to the forum, the latest posts wont update at all even though there are new posts being posted within the forum.. this rarely happens though.
Otsikko: Re: Recent Posts Automatic Updater
Kirjoitti: Major Minor - syyskuu 15, 2013, 10:09:02 IP
I found the JavaScript file that I'm pretty sure serves as the whole recent posts automatic updater function... Here it is:

kanyetothe.com/_shared/push.js?v910

I'm not to familiar with JavaScript... Could anyone explain what is going on within this code and also if it is a code designed straight from scratch, or a downloadable plugin?

What do you guys think? 


edit: after looking at the script more, I'm not too sure if that is the recent posts updater script.... hmm
Otsikko: Re: Recent Posts Automatic Updater
Kirjoitti: Major Minor - syyskuu 16, 2013, 03:05:43 IP
It appears that the file I previously linked has been changed... It still appears to be the same code, just now bunched together and a lot harder to read / decipher.  Oddly enough, the code was modified shortly after I posted a link to it on this forum... Maybe the creator of that website still visits this forum?  :o Probably just a coincidence...  ;D

But anyways, here is the original code before it was modified.. Again, I think this is the source for the automatic post updater and if anyone could confirm this for me or try to decipher what is going on within the code that would be great...

pastebin.com/ny8bRfwb
Otsikko: Re: Recent Posts Automatic Updater
Kirjoitti: All Colours Sam - syyskuu 16, 2013, 03:14:21 IP
Oh well, they probably don't want to share their code? it doesn't really matter since 80% of people who use SMF won't be able to achieve what they have.

Anyway, they are using Meteor which itself uses Node.js which is a low-level framework to handle HTTP request.

Since Node.js doesn't have the same "restrictions" as PHP does, they can quite happily handle "live" requests using Node/Meteor.

Unless you have the same infraestructure as they or at the very low your own un-managed server, you cannot replicate the exact same functionality.

You can mimic the functionality in pure PHP but the result won't be the same since PHP wasn't wrote for handling live HTTP request, theres PHPreact which is awesome and I've played with it before but it needs some requirements such as having your own server or at least a VM.
Otsikko: Re: Recent Posts Automatic Updater
Kirjoitti: Major Minor - syyskuu 16, 2013, 03:31:36 IP
Lainaus käyttäjältä: Suki - syyskuu 16, 2013, 03:14:21 IP
Oh well, they probably don't want to share their code? it doesn't really matter since 80% of people who use SMF won't be able to achieve what they have.

Anyway, they are using Meteor which itself uses Node.js which is a low-level framework to handle HTTP request.

Since Node.js doesn't have the same "restrictions" as PHP does, they can quite happily handle "live" requests using Node/Meteor.

Unless you have the same infraestructure as they or at the very low your own un-managed server, you cannot replicate the exact same functionality.

You can mimic the functionality in pure PHP but the result won't be the same since PHP wasn't wrote for handling live HTTP request, theres PHPreact which is awesome and I've played with it before but it needs some requirements such as having your own server or at least a VM.
Makes sense, thanks Suki!  :)

It seems like that forum has a lot of "next level" coding going on within their website... It made me realize that I still have a lot more reading and learning to do  :laugh:
Otsikko: Re: Recent Posts Automatic Updater
Kirjoitti: All Colours Sam - syyskuu 16, 2013, 03:38:15 IP
Well, it is not "next level" Node.js is just another alternative to build web applications, there is a huge fuss a round it because all the "cool kids" used to used it and rant about how PHP cannot compete with that.

It is actually pretty fun to work with its PHP counterpart: PHPreact but even PHPreact has to deal with the same limitations of PHP itself.

You can build an ajax call and retrieve the latest post every 5 seconds but it will take a toll on your server performance. Or you can use SSI.php to show pretty much the same block and it will be update on every page change or refresh.

Heres a nice article about PHP's limitations: http://software-gunslinger.tumblr.com/post/48215406921/php-is-meant-to-die-continued  read the first part first though.
Otsikko: Re: Recent Posts Automatic Updater
Kirjoitti: samborabora - syyskuu 16, 2013, 04:01:03 IP
Is there no mod or function built in that could fetch the posts and then simply be displayed in a sidebar with a little extra coding? I can't imagine how it would be THAT hard to just grab recent posts even few seconds and stick them in a widget?
Otsikko: Re: Recent Posts Automatic Updater
Kirjoitti: All Colours Sam - syyskuu 16, 2013, 04:11:08 IP
Lainaus käyttäjältä: samborabora - syyskuu 16, 2013, 04:01:03 IP
Is there no mod or function built in that could fetch the posts and then simply be displayed in a sidebar with a little extra coding? I can't imagine how it would be THAT hard to just grab recent posts even few seconds and stick them in a widget?

It isn't difficult at all... most if not all portals do that.  Theres even a SSI.php function already built and ready to be used...

The problem arise when you have an ajax call to retrieve the latest post/topic every X seconds. If you have the infrastructure then go for it.
Otsikko: Re: Recent Posts Automatic Updater
Kirjoitti: samborabora - syyskuu 17, 2013, 08:13:05 AP
Okay, can you basically describe what it would involve to build or use an infrastructure to access the function? Is it a hosting feature or something one installs or codes?
Otsikko: Re: Recent Posts Automatic Updater
Kirjoitti: margarett - syyskuu 17, 2013, 08:30:24 AP
Not really, it's just coding, really.

What Suki means as infrastructure is SERVER resources: a VPS or another kind of high-resources hosting because it will hammer your server like hell :)
Otsikko: Re: Recent Posts Automatic Updater
Kirjoitti: samborabora - syyskuu 17, 2013, 10:07:51 AP
Hows about Hawkhost's Standard plan, would that have what it takes? (Sorry, not sure if this constitutes as advertising or anything, but I'm not sure how else to reference my current providers plan?)
Otsikko: Re: Recent Posts Automatic Updater
Kirjoitti: Arantor - syyskuu 17, 2013, 10:13:28 AP
Unlikely.

Consider what's actually going on with this... every single user on the site, guests included, is making a call to the website every few seconds, each of which requires thousands of lines of code to be executed. If you have 100 users, that's 100 requests every 5 seconds - averaging 20 requests per second, far far more than most shared servers can handle.

Heck even a VPS might struggle with that.
Otsikko: Re: Recent Posts Automatic Updater
Kirjoitti: Major Minor - syyskuu 17, 2013, 02:39:14 IP
Lainaus käyttäjältä: Arantor - syyskuu 17, 2013, 10:13:28 AP
Unlikely.

Consider what's actually going on with this... every single user on the site, guests included, is making a call to the website every few seconds, each of which requires thousands of lines of code to be executed. If you have 100 users, that's 100 requests every 5 seconds - averaging 20 requests per second, far far more than most shared servers can handle.

Heck even a VPS might struggle with that.
And if you look at their forum it says there are more than 6000 users online.  So the requests must me much more demanding then what you describe. I'm sure there's got to be a different, more efficient way of doing this, right?
Otsikko: Re: Recent Posts Automatic Updater
Kirjoitti: Arantor - syyskuu 17, 2013, 02:51:14 IP
No, there isn't. The way they're doing it is indeed a new poll every few seconds which does necessitate a lot of extra load in the process.

However they were quite smart about it, so let's break it down and explain why what they're doing actually fits everything I originally pointed out.

The polling is done every few seconds to live.kanyetothe.com rather than the main site. This extra subdomain has a different IP address - very likely a different server entirely (hint: this is a small cluster, a smaller version of what a datacenter is, a lot of machines doing the work), this extra server does not appear to be running PHP at all and certainly doesn't bother doing authentication.

This saves you a fair amount of work, because you only need to care about the most important data, i.e. the topic data itself, but doesn't work if you want to be user-specific about it, you can only ever have the stuff that's completely public in there.

Those 6000 users online can easily generate thousands of requests per minute, hundreds per second in most cases - and a suitably expensive server can probably handle that, especially if it's using nginx with something like Node.js on the backend to manage it and keep it transiently active.

This is not something you will be able to do on low end shared hosting. Hell, this will require a minimum of a VPS to pull off, more likely a dedicated server - which means you're getting into the realms of hundreds of dollars a month to run it.
Otsikko: Re: Recent Posts Automatic Updater
Kirjoitti: samborabora - syyskuu 18, 2013, 08:35:31 AP
What's the easiest way of adding recent posts to the right side of the board, without an auto refresh? Would that be okay for shared hosting
Otsikko: Re: Recent Posts Automatic Updater
Kirjoitti: Arantor - syyskuu 18, 2013, 08:37:50 AP
Easiest way is to use a portal, they all have a recent posts block (and come with a sidebar)
Otsikko: Re: Recent Posts Automatic Updater
Kirjoitti: samborabora - syyskuu 18, 2013, 02:09:53 IP
To be honest, I'd rather not go through the whole front end of a portal, I'd rather just recode a sidebar into the main boards template, is there anything by default SMF that can be called to give out recent posts?
Otsikko: Re: Recent Posts Automatic Updater
Kirjoitti: Arantor - syyskuu 18, 2013, 02:19:41 IP
You do know that the portals can be configured not to do that, right?
Otsikko: Re: Recent Posts Automatic Updater
Kirjoitti: samborabora - syyskuu 19, 2013, 06:13:34 AP
Do you mean it's possible to just use a portal to display a sidebar with recent posts?
Otsikko: Re: Recent Posts Automatic Updater
Kirjoitti: Arantor - syyskuu 19, 2013, 08:31:27 AP
Sure it is. Pretty sure all the portals can do that.
Otsikko: Re: Recent Posts Automatic Updater
Kirjoitti: samborabora - syyskuu 19, 2013, 03:47:34 IP
You're right, I did it with SP, thanks!