0

I'm making a call to an internal endpoint in order to try and speed up a task.

I don't need to wait for the task (that awaits at that endpoint) to complete for my script to move on, but it's still waiting to finish. I'm using the following:

$argsForRequest = array(
'agency_code' => '1234',
'another_param_here' => $myVar,
'timeout'   => 0.01,
'blocking'  => false,
'sslverify' => false,
);

$request = new WP_REST_Request( 'POST', '/my/custom/endpoint' );
$request->set_query_params( $argsForRequest );
$response = rest_do_request( $request );

Any idea on what I could be doing wrong?

Thanks!

3

1 Answer 1

1

rest_do_request does not make a HTTP request to the REST API. rest_do_request handles a request object directly. WP_REST_Request and rest_do_request are for handling requests, not making them. This is why your attempt to make it non-blocking failed.

If you want to make a non-blocking request to the REST API, you have to make a HTTP request using wp_remote_post to the desired endpoint.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.