note 110649 modified in function.session-start by danbrown

From: Date: Thu, 06 Dec 2012 14:15:16 +0000
Subject: note 110649 modified in function.session-start by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-192311@lists.php.net to get a copy of this message
When you have an import script that takes long to execute, the browser seem to lock up and you cannot access the website anymore. this is because a request is reading and locking the session file to prevent corruption. you can either - use a different session handler with session_set_save_handler() - use session_write_close() in the import script as soon you don't need session anymore (best moment is just before the long during part takes place), you can session_start when ever you want and as many times you like if your import script requires session variables changed. example <?php session_start(); //initiate / open session $_SESSION['count'] = 0; // store something in the session session_write_close(); //now close it, # from here every other script can be run (and makes it seem like multitasking) for($i=0; $i<=100; $i++){ //do 100 cycles session_start(); //open the session again for editing a variable $_SESSION['count'] += 1; //change variable session_write_close(); //now close the session again! sleep(2); //every cycle sleep two seconds, or do a heavy task } ?> --was-- When you have an import script that takes long to execute, the browser seem to lock up and you cannot access the website anymore. this is because a request is reading and locking the session file to prevent corruption. you can either - use a different session handler with session_set_save_handler() - use session_write_close() in the import script as soon you don't need session anymore (best moment is just before the long during part takes place), you can session_start when ever you want and as many times you like if your import script requires session variables changed. example <? session_start(); //initiate / open session $_SESSION['count'] = 0; // store something in the session session_write_close(); //now close it, # from here every other script can be run (and makes it seem like multitasking) for($i=0; $i<=100; $i++){ //do 100 cycles session_start(); //open the session again for editing a variable $_SESSION['count'] += 1; //change variable session_write_close(); //now close the session again! sleep(2); //every cycle sleep two seconds, or do a heavy task } ?> http://php.net/manual/en/function.session-start.php

« previous php.notes (#192311) next »