title: Execute php code after giving the user 200 response
body: <p>I am building an API. In it, there is some code that does not need to be executed for giving a response to the user. So I would like to give the response after the mandatory code is executed and also run the remaining code in the background.</p>
  
  <p>This is a Linux server running apache and PHP7.2</p>
  
  <pre class="lang-php prettyprint-override"><code>        ignore_user_abort(true);
          set_time_limit(0);
  
          ob_start();
  
          $api_key = $request-&gt;get('api_key');
          $clientToken = ClientToken::where('token', $api_key)-&gt;where('is_blocked', 0)-&gt;get();
          if (count($clientToken) &gt; 0) {
              $dateTime = date_create_from_format('d-m-Y H:i:s a', $request-&gt;get('date_time'));
              $missCallRequest = new MissCallRequest();
              $missCallRequest-&gt;client_token_id = $clientToken[0]-&gt;id;
              $missCallRequest-&gt;called_number = "+" . $request-&gt;get('called_number');
              $missCallRequest-&gt;caller_number = $request-&gt;get('caller_number');
              $missCallRequest-&gt;datetime = date_format($dateTime, 'Y-m-d H:i:s');
              $missCallRequest-&gt;operator = $request-&gt;get('operator');
              $missCallRequest-&gt;circle = $request-&gt;get('circle');
              $missCallRequest-&gt;request_url = urldecode($request-&gt;fullUrl());
              $missCallRequest-&gt;save();
  
          }
  
          $response = [
              "status" =&gt; 200,
              "message" =&gt; "Request Received",
          ];
  
          echo json_encode($response); // send the response
  
          // Get the size of the output.
          $size = ob_get_length();
  
          // Disable compression (in case content length is compressed).
          header("Content-Encoding: none");
  
          // Set the content length of the response.
          header("Content-Length: {$size}");
  
          // Close the connection.
          header("Connection: close");
  
          // Flush all output.
          ob_end_flush();
          ob_flush();
          flush();
  
          echo "hello";
  </code></pre>
  
  <p>This is responding after the mandatory code but it's not executing the rest of the code after responding.</p>