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
Ad

More Related Content

Similar to Asynchronous WordPress (20)

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
 
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 deployment
bsadd
 
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
 
WordPress development paradigms, idiosyncrasies and other big words
WordPress development paradigms, idiosyncrasies and other big wordsWordPress development paradigms, idiosyncrasies and other big words
WordPress development paradigms, idiosyncrasies and other big words
TomAuger
 
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
 
Introduction to WordPress Security
Introduction to WordPress SecurityIntroduction to WordPress Security
Introduction to WordPress Security
Shawn Hooper
 
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 deployment
bsadd
 
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
 
WordPress development paradigms, idiosyncrasies and other big words
WordPress development paradigms, idiosyncrasies and other big wordsWordPress development paradigms, idiosyncrasies and other big words
WordPress development paradigms, idiosyncrasies and other big words
TomAuger
 

More from Aaron Brazell (9)

Wp cli-wcbalt
Wp cli-wcbaltWp cli-wcbalt
Wp cli-wcbalt
Aaron Brazell
 
Wp cli
Wp cliWp cli
Wp cli
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 Authentication
Aaron Brazell
 
American University WordPress Theming Lecture
American University WordPress Theming LectureAmerican University WordPress Theming Lecture
American University WordPress Theming Lecture
Aaron 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 Leagues
Aaron Brazell
 
Findability Abwc2008
Findability Abwc2008Findability Abwc2008
Findability Abwc2008
Aaron Brazell
 
Capuano Letter
Capuano LetterCapuano Letter
Capuano Letter
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 Authentication
Aaron Brazell
 
American University WordPress Theming Lecture
American University WordPress Theming LectureAmerican University WordPress Theming Lecture
American University WordPress Theming Lecture
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 Leagues
Aaron Brazell
 
Findability Abwc2008
Findability Abwc2008Findability Abwc2008
Findability Abwc2008
Aaron Brazell
 
Ad

Recently uploaded (20)

Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Ad

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: [email protected] • Github: https://github.com/technosailor • WP.org Profile: https://profiles.wordpress.org/technosailor
  • 17. Aaron Brazell • @technosailor • www.technosailor.com