## Non-blocking file_put_contents in function.php

Question

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' );

0
1 year 2020-07-22T11:10:34-05:00 0 Answers 46 views 0