WordPress Development Asked by Mustafa on November 26, 2021
I have a function in function.php which is called on save_post. Currently, when the user is publishing or updating a post, this function will execute but it will take a lot of time.
What is the easiest way so this function run in a background process – non-blocking?
function export_all_in_json() {
file_put_contents(ABSPATH.'all.json', fopen('https://example.com/api/all/get_all_content/', 'r'));
}
add_action( 'save_post', 'export_all_in_json' );
Instead of contacting the remote site to get the information in an expensive HTTP request, why not have the remote site send you the data at regular intervals?
all.json
Now we have a completely asynchronous non-blocking system. Why fetch the data when it can be given to you?
This gives us several bonuses:
save_post
filter can be completely removed making post saving fasterAnswered by Tom J Nowell on November 26, 2021
Maybe you can use Action Scheduler to trigger a single asyncronous event. Just like a cronjob but triggered one time.
Answered by Carlos Faria on November 26, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP