admin管理员组

文章数量:1297125

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!

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!

Share Improve this question asked Oct 25, 2020 at 18:23 Best Dev TutorialsBest Dev Tutorials 4451 gold badge7 silver badges21 bronze badges 3
  • Hi, did you find the solution ? – Gnanasekaran Loganathan Commented Mar 24, 2021 at 21:03
  • @GnanasekaranLoganathan Yup I posted my solution. – Best Dev Tutorials Commented Mar 29, 2021 at 20:12
  • Thank you for sharing the solution. – Gnanasekaran Loganathan Commented Mar 29, 2021 at 20:20
Add a comment  | 

1 Answer 1

Reset to default 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.

本文标签: Making internal rest requests nonblocking