Method for running large PHP script from WP admin

Skip to first unread message

Aug 10, 2021, 6:20:51 PM8/10/21
to Minneapolis St. Paul WordPress User Group
Hi all,

I have a large PHP script that I'm triggering from a WP admin POST function.  It probably takes about four or five minutes to complete, which is longer than any script I've worked with previously, so I need to take additional steps.

Right now, the POST request fails with a 504 error after about 30 seconds because it hasn't gotten any response.  The triggered script continues running for a while, but is also not being completed (it worked fine locally, but is not completing on my deployment server).  I probably just need to adjust my server's PHP settings or streamline my import script better.

I'm wondering if anyone has a recommendation for a general method to use to send repeated updates to the browser making the POST request and create something like a progress bar.  I can imagine how that might work, but want to make sure I don't miss a useful tool and build too much from scratch.

- Peter

Nick Ciske

Aug 10, 2021, 6:36:06 PM8/10/21
Options here are:
  1. Increase the overall timeout for that script (if PHP/Apache/Nginx allow scripts to do that) or all PHP scripts (but be warned that can mean any script can run super long and eat up your PHP workers, so avoid this if you can).
  2. If you can, go asynchronous with something like Action Scheduler and let it chew away in the background. You can hack something together using QP cron and posting to itself if the timeout is near, but that’s a solved problem with AS… so try not to reinvent the wheel ;-)
  3. Go CLI - the PHP CLI (or WP CLI) doesn’t have timeouts because it’s not running in a web worker. This can be an option for large batch jobs, provided you can rework your script to run in the CLI vs web server (as many assumptions are not true in the CLI).
Bumping PHP version, RAM, or server size may also help… a bit, but 4-5m means you’re hitting a serious bottleneck somewhere (likely in the WPDB layer).

Nick Ciske 
Nick Ciske Photo   |   612-564-1626 x702
Custom technology solutions that make businesses more effective, productive, and profitable.

Peter VanKoughnett

Aug 11, 2021, 12:37:49 PM8/11/21
Thanks Nick, Action Scheduler didn't take long to get up and running and is working well for me 🙂

You received this message because you are subscribed to the Google Groups "Minneapolis St. Paul WordPress User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
Reply all
Reply to author
0 new messages