When submitting a form I want to call an additional function that will connect to a webservice. Because of the slow response time of that webservice, I don’t want the page to keep loading untill the process is done.
Instead the action should be fired/called and run on the background.
What is the best way to achieve this?
1 Answer
Use the WordPress HTTP API with a low timeout & blocking disabled. It’s what WordPress core does to spawn the cron API:
wp_remote_get(
$url,
array(
'timeout' => 0.01,
'blocking' => false,
'sslverify' => false,
)
);