Allow custom REST route to return before doing long operation

Question

I have a custom REST route that imports a CSV file. Everything works so far, but I get a timeout error because it’s a really big CSV and it takes a long time. I want to make my REST route start the import process, then return a response while continuing to import.

register_rest_route('lws-admin/v1', '/customer/import', array(
  'methods' => 'POST',
  'callback' => function($request) {
    // *start really long operation*

    return array(
      'message' => 'import started'
    );
  }
));

--------------------------------------------------

>>> Share a link to this question, just copy and paste the code bellow on your web page <<<

<a href="https://www.wptricks.com/question/allow-custom-rest-route-to-return-before-doing-long-operation/">

Allow custom REST route to return before doing long operation</a>
0
, , chrispytoes 3 months 0 Answers 69 views 0

Leave an answer