Threads and concurrency

While PHP does have support for multithreaded execution, it’s seldom used in the WordPress ecosystem. Although you may not require this concept for your work, it’s beneficial to review it as a refresher.

In a typical PHP context, it’s important to note that each HTTP request to PHP/WordPress spins up an independent PHP process. Each process is synchronous, so any expensive queries, such as wp_remote_get(), database queries, or other lengthy processing, should be cached or delegated to a secondary HTTP request using WP AJAX or the REST API.

See Transients, which cache to the database by default, but use the PHP Object Cache if available.

References:

  1. Threads and Concurrency
  2. Operating System: Threads and Concurrency – Article by Akhand Mishra.