I have something like this :
<?php
$perform_check = 1; #Checks data with ID : 1
while(true)
{
#code
}
?>
But some data must be updated in this process, is it possible to update this data from another document?
I tried something like this :
index.php
<?php
setcookie("data", 19, time()+3600);
?>
and
loop.php
<?php
while(true)
{
if($perform_check!=$_COOKIE[data]) $perform_check = $_COOKIE[data];
#rest of code
flush();
sleep(0.3);
}
?>
But it doesn’t work. I also tried $_SESSION but the page crashes on session_start().
Is it somehow possible?
Cookies are sent as a HTTP header when PHP is sending a response through the web server (for example Apache2).
All HTTP headers are sent before any output. If you output anything, headers are sent (including the set-cookie header) before the output.
After you
flush()the first time you can no longer set cookies or other headers.If you want a progress indicator or updates, you need to initiate whatever operation you are doing using javascript and do polling at an interval. In the process with the loop you need to save the progress in a shared memory, in a file or in a database (in this order of preference), then read that data using the process started by javascript progress check/updates check.