3

I am developing an api which processes user request and sends them response in JSON format. I want to send JSON response and then do the work which takes more time e.g. sending mail to the user. Script pseudo code

  1. do validations
  2. if its valid then update database
  3. if d/b update successful then send JSON response
  4. get out of ifs and else of validations
  5. send email to the user

I referred this stackoverflow solution which runs exactly as I wanted in browser but when I test it in POSTMAN or in device where this API is being used I don't get the exact response. Browser responds quickly while loading the entire page but postman doesn't display result till the end of execution, e.g. code

<?php
ignore_user_abort(true);
set_time_limit(0);
ob_start();
// do initial processing here
echo json_encode(array("date", strtotime(date('Y-m-d H:i:s')))) . "<br />"; // send the response

header('Connection: close');
header('Content-Length: '.ob_get_length());
ob_end_flush();
ob_flush();
flush();

for ($i = 0; $i < 999999999; $i++) {

}
echo json_encode(array("date", strtotime(date('Y-m-d H:i:s'))));



?>

above code works fine in browser but when called in POSTMAN REst client it executes for longer time Thanks in advance

Community
  • 1
  • 1
  • 1
    Can you state your problem more precisely? What do you mean by "I don't get the exact response"? – Red Bottle May 12 '17 at 10:41
  • when I run this php file in browser I am getting the json response and the php page keeps on loading (with loading symbol near page title) but when I call this api from POSTMAN rest client then it doesn't display json response untill file execution is complete – Nikhil Tembkar May 12 '17 at 10:47

0 Answers0