[wp-trac] [WordPress Trac] #23216: Create "WP Heartbeat" API

WordPress Trac noreply at wordpress.org
Sun Jan 20 22:27:34 UTC 2013


#23216: Create "WP Heartbeat" API
----------------------------+------------------
 Reporter:  azaozz          |       Owner:
     Type:  task (blessed)  |      Status:  new
 Priority:  normal          |   Milestone:  3.6
Component:  Administration  |     Version:
 Severity:  normal          |  Resolution:
 Keywords:  autosave-redo   |
----------------------------+------------------

Comment (by azaozz):

 Replying to [comment:21 TJNowell]:
 > Rather than a strict 15 seconds, maybe Wordpress should send back a
 value specifying a suggested time for the client to wait until the next
 'beat'...

 Yes, was thinking/testing something similar. Perhaps we can throttle the
 beat when user B performs an action that would need response from user A
 like opening a post that is already being edited by user A, etc.

 We can add support for this on both sides, PHP and JS.

 Generally we have three options:

 '''Standard polling'''
 - 15 seconds interval, simple to implement, simple to use and understand.
 - Covers all current user cases, however can "feel" slow when taking over
 a post lock.
 - Possibly add throttling to improve user experience.

 '''Long polling'''
 In essence it would look something like this on the PHP side (on the JS
 side this is a standard XHR that runs in a loop):

 {{{
 function wp_poll() {
         $out = '';

         for ( $i = 0; $i < 5; $i++ ) {
                 $val = apply_filters( 'wp_poll', array() );

                 if ( ! empty($val) ) {
                         echo JSON.encode($val);
                         exit;
                 }

                 sleep(2);
         }

         echo $out;
         exit;
 }
 }}}

 - Better user experience than standard polling as it will deliver
 notifications to the browser faster (speed is only limited by the time
 needed to do a XHR). Also can be used when/if we implement concurrent
 editing.
 - Ties resources on the server. There will be one process per user that
 will be running almost constantly.
 - Needs to poll the DB.
 - May run into problems with caching in PHP.

 '''Hybrid'''
 Start with polling and switch to long-polling when needed instead of
 throttling (as described above). This still needs some time to switch both
 user A and user B to long-polling, but preforms better after that.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/23216#comment:24>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list