I found some core php
code from Google. I tested this code is working fine. But While I am using this code in my Yii application this code is not working.
Please check my code below:
/* filename: test.php */
date_default_timezone_set('Asia/Calcutta');
ini_set("error_log", "error.log");
echo "We'll email you as soon as this is done.";
$size = ob_get_length();
header("Content-Length: $size");
header('Connection: close');
// flush all output
ob_end_flush();
//ob_flush();
flush();
sleep(30);
/* notification and other code here */
error_log("Background process end");
When I am testing above code in separate file like test.php
this is working fine. But Not working in Yii controller action.
I have set sleep 30 seconds of my background process execution time. 1st time while I hit my controller action in browser this is working and Page reload couple of microseconds after. While again I refresh this page or any other pages That pages reloading until my 1st execution not done.
Ref:
http://php.net/manual/en/features.connection-handling.php
How to fix it?