Skip to content

Instantly share code, notes, and snippets.

@erlangparasu
Last active October 11, 2019 02:26
Show Gist options
  • Select an option

  • Save erlangparasu/f1821f87ec9c2c4bb13d8de9651bc93a to your computer and use it in GitHub Desktop.

Select an option

Save erlangparasu/f1821f87ec9c2c4bb13d8de9651bc93a to your computer and use it in GitHub Desktop.
<?php
// Preparing response data.
$response = json_encode([
'success' => true,
'time' => date('Y-m-d H:i:s')
]);
// Keep process running after
// connection closed by the browser.
ignore_user_abort(true);
// Kirim header sebagai signal agar
// browser menampilkan data dan browser langsung
// menutup koneksi.
header('Content-Type: application/json');
header('Connection: close');
header('Keep-Alive: timeout=0, max=0');
header('Content-Length: '.mb_strlen($response));
echo $response;
ob_flush();
flush();
// Now this script is disconnected from browser
// but proccess still active.
// Let's run the code behind the scenes
sleep(10); // eg. request REST API
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment