SlideShare a Scribd company logo
1 of 17
Download to read offline
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 2016Ian 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 2014cklosowski
 
Introduction to WordPress Security
Introduction to WordPress SecurityIntroduction to WordPress Security
Introduction to WordPress SecurityShawn 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 2014Amazon 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 DevelopmentRyan Welcher
 
The Web Application Hackers Toolchain
The Web Application Hackers ToolchainThe Web Application Hackers Toolchain
The Web Application Hackers Toolchainjasonhaddix
 
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 dataConnected Data World
 
YQL: Select * from Internet
YQL: Select * from InternetYQL: Select * from Internet
YQL: Select * from Internetdrgath
 
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 LibraryBrian 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 2010Brad 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 StreamLetsConnect
 
Elegant Rest Design Webinar
Elegant Rest Design WebinarElegant Rest Design Webinar
Elegant Rest Design WebinarStormpath
 
WordPress Hooks (Actions & Filters)
WordPress Hooks (Actions & Filters)WordPress Hooks (Actions & Filters)
WordPress Hooks (Actions & Filters)MuhammadKashif596
 

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 PortfoliosAaron 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
 
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
 

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

New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 

Recently uploaded (20)

New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 

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