I am trying to continue a PHP Script after the page/connection is closed.
Users will POLL the script in every 1 hour, I want to return some json output and want to c
If you are using PHP-FPM, a cleaner and more versatile solution would be to simply execute fastcgi_finish_request();
From PHP.net's documentation
This function flushes all response data to the client and finishes the request. This allows for time consuming tasks to be performed without leaving the connection to the client open.
This is how Symfony handles its onTerminate.