I want to create a plugin that does some work in the background. I have a user interface in the admin backend where I have some buttons:

  • start fetching posts
  • stop fetching

When I press start fetching the plugin fetches some texts from an external API and creates a WordPress post for each text. But that are about 500.000 texts which have to be fetched. Since WordPress is based on PHP and I am not able to activate ZTS (thread-safety) for PHP on my webserver, each request for each text is made sequentially

  1. send request to API
  2. process the response
  3. create a WordPress post (and maybe category) for the text
  4. if there are texts left, goto 1.

So for about 500.000 texts this takes a lot of time. I wanted to know if you have an idea or a solution how to make the script faster or maybe how to use multi-threading, even if I don't have the ability to activate ZTS.

1 Answer 1


You need to use WP Background Processing which fire off non-blocking asynchronous requests.

WooCommerce also use this for background processing. Check the file /includes/libraries/wp-background-process.php

  • Nice! That looks really great, I'll try that out. Thanks!
    – beeef
    Aug 20, 2017 at 14:47
  • OK, that isn't really what I was looking for. You're right, the requests are made asynchronous, but one after one. What I need is something to make parallel requests.
    – beeef
    Aug 20, 2017 at 15:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.