asynchronous wordpress

10
Aaron Brazell • @technosailor • www.technosailor.com ASYNCHRONOUS WORDPRESS OFFLOADING HOOKED EVENTS TO INCREASE PAGE SPEED

Upload: aaron-brazell

Post on 15-Apr-2017

7.153 views

Category:

Engineering


0 download

TRANSCRIPT

Page 1: Asynchronous WordPress

Aaron Brazell • @technosailor • www.technosailor.com

A S Y N C H R O N O U S W O R D P R E S S

O F F L O A D I N G H O O K E D E V E N T S T O I N C R E A S E PA G E S P E E D

Page 2: Asynchronous WordPress

Aaron Brazell • @technosailor • www.technosailor.com

T H E P R O B L E M( D R A M AT I C T H E M E M U S I C )

Page 3: Asynchronous WordPress

Aaron Brazell • @technosailor • www.technosailor.com

• Every Time WordPress loads a page, events are fired.

• Plugins typically hook events into init, admin_init, plugins_loaded, or save_post to fire events

• Every event takes time to complete

• Many dozens of events, all waiting to finish running, add overhead to WordPress.

Page 4: Asynchronous WordPress

Aaron Brazell • @technosailor • www.technosailor.com

P O S S I B L E P R O B L E M S C E N A R I O S

• External API Request (Facebook/Twitter? Mailkimp?)

• Saving a Post

• Requesting information about a user when a user is created.

Page 5: Asynchronous WordPress

- S O M E O N E W H O B A D LY M A N G L E D T H E Q U O T E

“Asynchronous Events are not the heroes we want; they are the heroes we need.”

Photo Credit: V Threepio, via Flickr, Creative Commons

Page 6: Asynchronous WordPress

T E C H C R U N C H A S Y N C L I B R A R Y

• TechCrunch had extremely long process times, particularly with their CrunchBase API.

• API calls were required to repopulate cached results.

• Eric Mann (@ericmann) and John Bloch (@johnpbloch) built a library to offload tasks to asynchronous equivalents

• Runs on `shutdown` hook

Photo Credit: Charlyn Wee, via Flickr Creative Commons

Page 7: Asynchronous WordPress

Aaron Brazell • @technosailor • www.technosailor.com

O V E R V I E W O N H O W T O U S E

• Bundle the WP_Async library in any theme or plugin and require it. It can also be installed as a standalone plugin.

• Create a subclass that extends WP_Async_Task

• Include a prepare_data() and run_action() method (Details in the documentation)

• Include a protected $action variable that is set to the hook name you wish to run asynchronously.

• Hook events on wp_async_{$action} (e.g. wp_async_transition_post_status)

Page 8: Asynchronous WordPress

Aaron Brazell • @technosailor • www.technosailor.com

R E F E R E N C E S

• TechCrunch Open Sources its WordPress Async Task Library: http://techcrunch.com/2014/07/31/wp-async-task-our-new-open-source-library/

• Asynchronous WordPress, by 10up: http://techcrunch.com/2014/07/31/wp-async-task-our-new-open-source-library/

• Github: https://github.com/techcrunch/wp-async-task/

• Demo Plugin: https://github.com/technosailor/wcbalt-async-wp

• This Presentation: http://www.slideshare.net/technosailor/asynchronous-wordpress

Page 9: Asynchronous WordPress

Aaron Brazell • @technosailor • www.technosailor.com

A A R O N B R A Z E L L

• Sr. Web Engineer, 10up

• We’re Hiring Project Managers, WordPress/PHP Engineers and Front End UX Engineers (http://is10uphiring.com/)

• Twitter: http://technosailor.com/twitter

• Email: [email protected]

• Github: https://github.com/technosailor

• WP.org Profile: https://profiles.wordpress.org/technosailor

Page 10: Asynchronous WordPress

Aaron Brazell • @technosailor • www.technosailor.com