SlideShare a Scribd company logo
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 TO I N C R E A S E PA G E S P E E D
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 )
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.
Aaron Brazell • @technosailor • www.technosailor.com
P O S S I B L E S C E N A R I O S
( S I D E WAY S G L A N C E )
Aaron Brazell • @technosailor • www.technosailor.com
E X T E R N A L A P I R E Q U E S T
• Every page load, a site is expected to send a request
to an external API to get the most up to date
information.
• The natural place to make this event happen is on the
init hook.
• The third party API is extremely slow or maybe down
and WordPress must wait up to 30 seconds for the
failure to become known before moving on to the next
event.
Aaron Brazell • @technosailor • www.technosailor.com
S AV I N G A P O S T
• Saving posts is potentially one of the most expensive
hooks in WordPress
• There are different kinds of saves: Autosaves. Ajax
events. Non-content saves (Think attachments)
• Actions fire in chronological order. There is no limit to
the number of events that can fire on a hook.
• Virtually any plugin action requiring a “state” update -
meta, API requests, etc - fire on save_post.
- 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
T E C H C R U N C H
A S Y N C L I B R A RY
• 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
Aaron Brazell • @technosailor • www.technosailor.com
S T E P S TO I M P L E M E N T
• Install the WP_Async_Task class as a self-contained plugin or
bundle with plugin or theme as separate class. It will only ever be
included one time regardless.
• Create a subclass that extends WP_Async_Task for each hook
that needs to be fired asynchronously.
• Each subclass must contain two methods and a protected
variable $action - prepare_data() and run_action(). The
$action variable must be the name of the hook you’re providing
an alternative for. e.g protected $action = ‘save_post’;
• Hook asynchronous event into wp_async_{action} (e.g.
wp_async_save_post) and pass identical parameters.
Aaron Brazell • @technosailor • www.technosailor.com
E X T E N D I N G T H E
P R E PA R E _ D ATA ( ) M E T H O D
Aaron Brazell • @technosailor • www.technosailor.com
E X T E N D I N G T H E
P R E PA R E _ D ATA ( ) M E T H O D
• Method runs first. Receives a numerical array passed via
func_get_args(). PROTIP: For insight, print_r()
this array to your error log.
• Modify, sanitize and assign scalar values to a return
array that includes the arguments expected for the hook
you’re implementing. (e.g. save_post takes $post_id
and $post, so this method should set these up). Returns
an associative array with the expected parameters.
• For example, on save_post, return array( ‘post_id’
=> $post_id, ‘post’ => $post_object );
Aaron Brazell • @technosailor • www.technosailor.com
E X T E N D I N G T H E
R U N _ A C T I O N ( ) M E T H O D
Aaron Brazell • @technosailor • www.technosailor.com
E X T E N D I N G T H E R U N _ A C T I O N ( )
M E T H O D
• Think of this method as the method that actually runs
the processes the formulate the alternative hook.
• Receives the associative array created by the
prepare_data() method as a global $_POST array.
• Be sure to include wp_async_$this->action as:
do_action( ‘wp_async_’ . $this->action,
$variable1, $variable 2); to match the
definition of the core WordPress hook.
Aaron Brazell • @technosailor • www.technosailor.com
D E M O N S T R AT I O N
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
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: aaron.brazell@10up.com
• Github: https://github.com/technosailor
• WP.org Profile: https://profiles.wordpress.org/technosailor
Aaron Brazell • @technosailor • www.technosailor.com

More Related Content

Similar to Asynchronous WordPress

Introduction to WordPress Hooks 2016
Introduction to WordPress Hooks 2016Introduction to WordPress Hooks 2016
Introduction to WordPress Hooks 2016
Ian Wilson
 
TypeScript와 Flow: 
자바스크립트 개발에 정적 타이핑 도입하기
TypeScript와 Flow: 
자바스크립트 개발에 정적 타이핑 도입하기TypeScript와 Flow: 
자바스크립트 개발에 정적 타이핑 도입하기
TypeScript와 Flow: 
자바스크립트 개발에 정적 타이핑 도입하기
Heejong Ahn
 
Wrangling WP_Cron - WordCamp Grand Rapids 2014
Wrangling WP_Cron - WordCamp Grand Rapids 2014Wrangling WP_Cron - WordCamp Grand Rapids 2014
Wrangling WP_Cron - WordCamp Grand Rapids 2014
cklosowski
 
Intro To C++ - Class #21: Files
Intro To C++ - Class #21: FilesIntro To C++ - Class #21: Files
Intro To C++ - Class #21: Files
Blue Elephant Consulting
 
Introduction to WordPress Security
Introduction to WordPress SecurityIntroduction to WordPress Security
Introduction to WordPress Security
Shawn Hooper
 
(WEB301) Operational Web Log Analysis | AWS re:Invent 2014
(WEB301) Operational Web Log Analysis | AWS re:Invent 2014(WEB301) Operational Web Log Analysis | AWS re:Invent 2014
(WEB301) Operational Web Log Analysis | AWS re:Invent 2014
Amazon Web Services
 
Twas the night before Malware...
Twas the night before Malware...Twas the night before Malware...
Twas the night before Malware...
DoktorMandrake
 
Getting Started with WordPress Development
Getting Started with WordPress DevelopmentGetting Started with WordPress Development
Getting Started with WordPress Development
Ryan Welcher
 
The Web Application Hackers Toolchain
The Web Application Hackers ToolchainThe Web Application Hackers Toolchain
The Web Application Hackers Toolchain
jasonhaddix
 
Your Site Has Been Hacked, Now What?
Your Site Has Been Hacked, Now What?Your Site Has Been Hacked, Now What?
Your Site Has Been Hacked, Now What?
Michele Butcher-Jones
 
Server deployment
Server deploymentServer deployment
Server deploymentbsadd
 
Autodiscovery or The long tail of open data
Autodiscovery or The long tail of open dataAutodiscovery or The long tail of open data
Autodiscovery or The long tail of open data
Connected Data World
 
YQL: Select * from Internet
YQL: Select * from InternetYQL: Select * from Internet
YQL: Select * from Internet
drgath
 
Stop Reinventing The Wheel - The Ruby Standard Library
Stop Reinventing The Wheel - The Ruby Standard LibraryStop Reinventing The Wheel - The Ruby Standard Library
Stop Reinventing The Wheel - The Ruby Standard Library
Brian Hogan
 
Now That's What I Call WordPress Security 2010
Now That's What I Call WordPress Security 2010Now That's What I Call WordPress Security 2010
Now That's What I Call WordPress Security 2010
Brad Williams
 
Things you should know about WordPress (but were always too afraid to ask): W...
Things you should know about WordPress (but were always too afraid to ask): W...Things you should know about WordPress (but were always too afraid to ask): W...
Things you should know about WordPress (but were always too afraid to ask): W...
Michael McNeill
 
Mikkel Heisterberg - An introduction to developing for the Activity Stream
Mikkel Heisterberg - An introduction to developing for the Activity StreamMikkel Heisterberg - An introduction to developing for the Activity Stream
Mikkel Heisterberg - An introduction to developing for the Activity Stream
LetsConnect
 
Elegant Rest Design Webinar
Elegant Rest Design WebinarElegant Rest Design Webinar
Elegant Rest Design Webinar
Stormpath
 
WordPress Hooks (Actions & Filters)
WordPress Hooks (Actions & Filters)WordPress Hooks (Actions & Filters)
WordPress Hooks (Actions & Filters)
MuhammadKashif596
 
Platform cache
Platform cachePlatform cache
Platform cache
Amit Chaudhary
 

Similar to Asynchronous WordPress (20)

Introduction to WordPress Hooks 2016
Introduction to WordPress Hooks 2016Introduction to WordPress Hooks 2016
Introduction to WordPress Hooks 2016
 
TypeScript와 Flow: 
자바스크립트 개발에 정적 타이핑 도입하기
TypeScript와 Flow: 
자바스크립트 개발에 정적 타이핑 도입하기TypeScript와 Flow: 
자바스크립트 개발에 정적 타이핑 도입하기
TypeScript와 Flow: 
자바스크립트 개발에 정적 타이핑 도입하기
 
Wrangling WP_Cron - WordCamp Grand Rapids 2014
Wrangling WP_Cron - WordCamp Grand Rapids 2014Wrangling WP_Cron - WordCamp Grand Rapids 2014
Wrangling WP_Cron - WordCamp Grand Rapids 2014
 
Intro To C++ - Class #21: Files
Intro To C++ - Class #21: FilesIntro To C++ - Class #21: Files
Intro To C++ - Class #21: Files
 
Introduction to WordPress Security
Introduction to WordPress SecurityIntroduction to WordPress Security
Introduction to WordPress Security
 
(WEB301) Operational Web Log Analysis | AWS re:Invent 2014
(WEB301) Operational Web Log Analysis | AWS re:Invent 2014(WEB301) Operational Web Log Analysis | AWS re:Invent 2014
(WEB301) Operational Web Log Analysis | AWS re:Invent 2014
 
Twas the night before Malware...
Twas the night before Malware...Twas the night before Malware...
Twas the night before Malware...
 
Getting Started with WordPress Development
Getting Started with WordPress DevelopmentGetting Started with WordPress Development
Getting Started with WordPress Development
 
The Web Application Hackers Toolchain
The Web Application Hackers ToolchainThe Web Application Hackers Toolchain
The Web Application Hackers Toolchain
 
Your Site Has Been Hacked, Now What?
Your Site Has Been Hacked, Now What?Your Site Has Been Hacked, Now What?
Your Site Has Been Hacked, Now What?
 
Server deployment
Server deploymentServer deployment
Server deployment
 
Autodiscovery or The long tail of open data
Autodiscovery or The long tail of open dataAutodiscovery or The long tail of open data
Autodiscovery or The long tail of open data
 
YQL: Select * from Internet
YQL: Select * from InternetYQL: Select * from Internet
YQL: Select * from Internet
 
Stop Reinventing The Wheel - The Ruby Standard Library
Stop Reinventing The Wheel - The Ruby Standard LibraryStop Reinventing The Wheel - The Ruby Standard Library
Stop Reinventing The Wheel - The Ruby Standard Library
 
Now That's What I Call WordPress Security 2010
Now That's What I Call WordPress Security 2010Now That's What I Call WordPress Security 2010
Now That's What I Call WordPress Security 2010
 
Things you should know about WordPress (but were always too afraid to ask): W...
Things you should know about WordPress (but were always too afraid to ask): W...Things you should know about WordPress (but were always too afraid to ask): W...
Things you should know about WordPress (but were always too afraid to ask): W...
 
Mikkel Heisterberg - An introduction to developing for the Activity Stream
Mikkel Heisterberg - An introduction to developing for the Activity StreamMikkel Heisterberg - An introduction to developing for the Activity Stream
Mikkel Heisterberg - An introduction to developing for the Activity Stream
 
Elegant Rest Design Webinar
Elegant Rest Design WebinarElegant Rest Design Webinar
Elegant Rest Design Webinar
 
WordPress Hooks (Actions & Filters)
WordPress Hooks (Actions & Filters)WordPress Hooks (Actions & Filters)
WordPress Hooks (Actions & Filters)
 
Platform cache
Platform cachePlatform cache
Platform cache
 

More from Aaron Brazell

American University - American Observer Class - WordPress Portfolios
American University - American Observer Class - WordPress PortfoliosAmerican University - American Observer Class - WordPress Portfolios
American University - American Observer Class - WordPress Portfolios
Aaron Brazell
 
WordPress Third Party Authentication
WordPress Third Party AuthenticationWordPress Third Party Authentication
WordPress Third Party AuthenticationAaron Brazell
 
American University WordPress Theming Lecture
American University WordPress Theming LectureAmerican University WordPress Theming Lecture
American University WordPress Theming LectureAaron Brazell
 
JUSTICE Act of 2009
JUSTICE Act of 2009JUSTICE Act of 2009
JUSTICE Act of 2009
Aaron Brazell
 
WordCamp NY: Blogs and Making it Into the Big Leagues
WordCamp NY: Blogs and Making it Into the Big LeaguesWordCamp NY: Blogs and Making it Into the Big Leagues
WordCamp NY: Blogs and Making it Into the Big LeaguesAaron Brazell
 
Findability Abwc2008
Findability Abwc2008Findability Abwc2008
Findability Abwc2008Aaron Brazell
 
Capuano Letter
Capuano LetterCapuano Letter
Capuano Letter
Aaron Brazell
 

More from Aaron Brazell (9)

Wp cli-wcbalt
Wp cli-wcbaltWp cli-wcbalt
Wp cli-wcbalt
 
Wp cli
Wp cliWp cli
Wp cli
 
American University - American Observer Class - WordPress Portfolios
American University - American Observer Class - WordPress PortfoliosAmerican University - American Observer Class - WordPress Portfolios
American University - American Observer Class - WordPress Portfolios
 
WordPress Third Party Authentication
WordPress Third Party AuthenticationWordPress Third Party Authentication
WordPress Third Party Authentication
 
American University WordPress Theming Lecture
American University WordPress Theming LectureAmerican University WordPress Theming Lecture
American University WordPress Theming Lecture
 
JUSTICE Act of 2009
JUSTICE Act of 2009JUSTICE Act of 2009
JUSTICE Act of 2009
 
WordCamp NY: Blogs and Making it Into the Big Leagues
WordCamp NY: Blogs and Making it Into the Big LeaguesWordCamp NY: Blogs and Making it Into the Big Leagues
WordCamp NY: Blogs and Making it Into the Big Leagues
 
Findability Abwc2008
Findability Abwc2008Findability Abwc2008
Findability Abwc2008
 
Capuano Letter
Capuano LetterCapuano Letter
Capuano Letter
 

Recently uploaded

Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 

Recently uploaded (20)

Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 

Asynchronous WordPress

  • 1. 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 TO I N C R E A S E PA G E S P E E D
  • 2. 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 )
  • 3. 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.
  • 4. Aaron Brazell • @technosailor • www.technosailor.com P O S S I B L E S C E N A R I O S ( S I D E WAY S G L A N C E )
  • 5. Aaron Brazell • @technosailor • www.technosailor.com E X T E R N A L A P I R E Q U E S T • Every page load, a site is expected to send a request to an external API to get the most up to date information. • The natural place to make this event happen is on the init hook. • The third party API is extremely slow or maybe down and WordPress must wait up to 30 seconds for the failure to become known before moving on to the next event.
  • 6. Aaron Brazell • @technosailor • www.technosailor.com S AV I N G A P O S T • Saving posts is potentially one of the most expensive hooks in WordPress • There are different kinds of saves: Autosaves. Ajax events. Non-content saves (Think attachments) • Actions fire in chronological order. There is no limit to the number of events that can fire on a hook. • Virtually any plugin action requiring a “state” update - meta, API requests, etc - fire on save_post.
  • 7. - 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
  • 8. T E C H C R U N C H A S Y N C L I B R A RY • 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
  • 9. Aaron Brazell • @technosailor • www.technosailor.com S T E P S TO I M P L E M E N T • Install the WP_Async_Task class as a self-contained plugin or bundle with plugin or theme as separate class. It will only ever be included one time regardless. • Create a subclass that extends WP_Async_Task for each hook that needs to be fired asynchronously. • Each subclass must contain two methods and a protected variable $action - prepare_data() and run_action(). The $action variable must be the name of the hook you’re providing an alternative for. e.g protected $action = ‘save_post’; • Hook asynchronous event into wp_async_{action} (e.g. wp_async_save_post) and pass identical parameters.
  • 10. Aaron Brazell • @technosailor • www.technosailor.com E X T E N D I N G T H E P R E PA R E _ D ATA ( ) M E T H O D
  • 11. Aaron Brazell • @technosailor • www.technosailor.com E X T E N D I N G T H E P R E PA R E _ D ATA ( ) M E T H O D • Method runs first. Receives a numerical array passed via func_get_args(). PROTIP: For insight, print_r() this array to your error log. • Modify, sanitize and assign scalar values to a return array that includes the arguments expected for the hook you’re implementing. (e.g. save_post takes $post_id and $post, so this method should set these up). Returns an associative array with the expected parameters. • For example, on save_post, return array( ‘post_id’ => $post_id, ‘post’ => $post_object );
  • 12. Aaron Brazell • @technosailor • www.technosailor.com E X T E N D I N G T H E R U N _ A C T I O N ( ) M E T H O D
  • 13. Aaron Brazell • @technosailor • www.technosailor.com E X T E N D I N G T H E R U N _ A C T I O N ( ) M E T H O D • Think of this method as the method that actually runs the processes the formulate the alternative hook. • Receives the associative array created by the prepare_data() method as a global $_POST array. • Be sure to include wp_async_$this->action as: do_action( ‘wp_async_’ . $this->action, $variable1, $variable 2); to match the definition of the core WordPress hook.
  • 14. Aaron Brazell • @technosailor • www.technosailor.com D E M O N S T R AT I O N
  • 15. 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
  • 16. 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: aaron.brazell@10up.com • Github: https://github.com/technosailor • WP.org Profile: https://profiles.wordpress.org/technosailor
  • 17. Aaron Brazell • @technosailor • www.technosailor.com