[wp-hackers] Long Polling, Ajax and WordPress

Dagan Henderson Dagan.Henderson at epyllion.com
Tue Nov 1 15:22:18 UTC 2011


>I have two 'lists' that will need to have live updating enabled on.

>The one is the simple DB results I posted before. This is basically asking 'have any posts been added since I last checked', however wont this be different for whoever is logged in at that time? (I have no logged-out users). That is to say, user A may have seen the new post, and the cache is purged/updated, but user B hasn't had 'their' list updated yet...

No problem. Include the published_gmt value for each post and process it with your JavaScript. Basically, every ten seconds or so your AJAX script will query the server for the XML file (or perhaps JSON response) and look for anything new. You could also store a modified time in the file (so that you can use WordPress's current_time() function instead of the server's time) and only serve the file/response if the file has indeed been modified. That should limit bandwidth usage.

>The second 'list' might be a tad trickier. It's more like a Facebook activity stream, which will aggregate different post types and comments based on whether they have anything to do with the current user.

>Because this will be dynamic from one person to the next, how would I go about caching this (or any part of the jigsaw?)

You could always process the flat file on the server side. That'll result in miniscule resource usage (assuming you don't do any crazy loops that get out of control) and still give you the same performance boost because you don't have to query the DB each time.

-----Original Message-----
From: wp-hackers-bounces at lists.automattic.com [mailto:wp-hackers-bounces at lists.automattic.com] On Behalf Of Alex Hempton-Smith
Sent: Tuesday, November 01, 2011 8:11 AM
To: wp-hackers at lists.automattic.com
Subject: Re: [wp-hackers] Long Polling, Ajax and WordPress

Thanks all for your advice.

Id love to explore a static cache in the form of an XML file, updated only when new items are added, but there may be issues.

I have two 'lists' that will need to have live updating enabled on.

The one is the simple DB results I posted before. This is basically asking 'have any posts been added since I last checked', however wont this be different for whoever is logged in at that time? (I have no logged-out users). That is to say, user A may have seen the new post, and the cache is purged/updated, but user B hasn't had 'their' list updated yet...

The second 'list' might be a tad trickier. It's more like a Facebook activity stream, which will aggregate different post types and comments based on whether they have anything to do with the current user.

Because this will be dynamic from one person to the next, how would I go about caching this (or any part of the jigsaw?)

Maybe I'm missing something obvious, as I'm quiet inexperienced when it comes to caching etc.

Many thanks for your help,
Alex

Sent from my iPhone

On 1 Nov 2011, at 14:30, Hal Burgiss <hal at burgiss.net> wrote:

> On Tue, Nov 1, 2011 at 9:46 AM, Dagan Henderson < 
> Dagan.Henderson at epyllion.com> wrote:
>
>>> A different take on this ... since it seems to me a heavy handed use 
>>> of
>> resources if there is significant traffic, and the data could be 
>> cached (although a very short lived cache), and that way you don't 
>> have potentially many clients running the same query every few 
>> seconds. So,  I would think about a shell script that builds the cache server side:
>>
>> Rather than a long-running shell script (which violates some hosting 
>> provider TOS and requires SSH access), why not hook into 'edit_post,'
>> which is called for comments and post edits alike?
>>
>>
> Better, yes! That way cache is rebuilt only as needed.
>
> --
> Hal
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
wp-hackers at lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers


More information about the wp-hackers mailing list