Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

close ajax request from php before script ends

How do you close an ajax request from php before the script ends? Example: user requests php.php, which has the line: echo "phpphp", and after this line, the ajax request finishes and has the data "phpphp", but the PHP script keeps on running, without using processes or forking?

like image 463
John Smith Avatar asked Feb 14 '26 17:02

John Smith


1 Answers

How do i implement this scenario using PHP? has the answer. Set Connection close and Content length headers, with the flushing.

  ob_start();

  echo "111";
  header("Content-Length: ".ob_get_length());
  header("Connection: close");

  flush();
  somescript();
like image 76
John Smith Avatar answered Feb 17 '26 07:02

John Smith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!