I am attempting to update a large array of feeds into WordPress, using fetch_feeds. As can be expected, when going over 50 feeds the server is starting to time out. I would still like to update the feeds in bulk but without crashing the server.
Can you suggest a method through which I can break things down? Maybe using AJAX? Is that the best technique? Any examples I can look at?
You can try using wp cron functions, programing a feed import every 10 minutes or so, until you have nothing left in queue.
Example code:
It is essential only to run the scheduler on a activation hook, or else at every page load the crons will be rescheduled.
You’ve tried to extend the script’s maximum execution time with
set_time_limit()
? This will not cause the server to crash (because it has a memory limit too):I’m not sure what you mean with “breaking down” the script, you might want to have a second thought on that.
What you could do if there are to many rows in the feed’s XML you also could make your own import script and take care of its handle your own way by processing small part by small part.
More information about the XML parser can be found in the PHP manual.
When it comes down to high execution time scripts I usually split it up as simple as possible using ajax so here is a concept class that should get you started with creating an admin page and ajaxed import loop: