0

my application is set "session_handler" to Redis in php.ini,when I write the following code, Redis session storage is nil. My initial idea is a method to deal with time-consuming tasks and write current progressing value into the session variable, another method by ajax polling task progress.

session_start();
$i = 1;
while ($i <= 10)
{

    $_SESSION['process_sync'] = $i;
    $i++;
    sleep(1);
}
$msg = "processing is over";
session_destroy();
print $msg;

I do not know if sleep time is too long, Redis connection will be closed, but 1 second should not be a long time. Or $ _SESSION = "fang xing" assignment, Redis client did not immediately send orders to the Redis server, but in the queue cache, in other words this operation is not blocked, followed by the implementation of sleep, Redis client will put the above Said the queue data discarded? (I assume)

Who can give me talk about the principle :)

fang xing
  • 55
  • 1
  • 6
  • Sleeping in PHP has its uses, this is not one of them. A script in PHP should be designed to be finished executing asap. Polling or websockets are better ways to do this. – Xorifelse Oct 19 '16 at 03:47

2 Answers2

0

I think session is something client does not have a direct access to. I guess propagating progress by Ajax would be a better idea.

How to make progress bar with jQuery and PHP while waiting server process?

Community
  • 1
  • 1
Binus
  • 1,065
  • 7
  • 14
0

Session will be written to file after request shutdown.

Dennis Haarbrink
  • 3,738
  • 1
  • 27
  • 54
fang xing
  • 55
  • 1
  • 6