Ho riscontrato questo problema durante il tentativo di correggere il comportamento di blocco di $ _SESSION.
http://konrness.com/php5/how-to-prevent-blocking-php-requests/
Il file sessione rimane bloccata fino al completamento dello script o la sessione viene chiusa manualmente.
Quindi, per impostazione predefinita, una pagina dovrebbe aprire una sessione in modalità di sola lettura. Ma una volta aperto in sola lettura, deve essere chiuso e riaperto in modalità di scrittura.
const SESSION_DEFAULT_COOKIE_LIFETIME = 86400;
/**
* Open _SESSION read-only
*/
function OpenSessionReadOnly() {
session_start([
'cookie_lifetime' => SESSION_DEFAULT_COOKIE_LIFETIME,
'read_and_close' => true, // READ ACCESS FAST
]);
// $_SESSION is now defined. Call WriteSessionValues() to write out values
}
/**
* _SESSION is read-only by default. Call this function to save a new value
* call this function like `WriteSessionValues(["username"=>$login_user]);`
* to set $_SESSION["username"]
*
* @param array $values_assoc_array
*/
function WriteSessionValues($values_assoc_array) {
// this is required to close the read-only session and
// not get a warning on the next line.
session_abort();
// now open the session with write access
session_start([ 'cookie_lifetime' => SESSION_DEFAULT_COOKIE_LIFETIME ]);
foreach ($values_assoc_array as $key => $value) {
$_SESSION[ $key ] = $value;
}
session_write_close(); // Write session data and end session
OpenSessionReadOnly(); // now reopen the session in read-only mode.
}
OpenSessionReadOnly(); // start the session for this page
Poi quando si va a scrivere un certo valore:
WriteSessionValues(["username"=>$login_user]);
Non avviare una nuova sessione se una vecchia sta correndo? –
possibile duplicato di [Come sapere se una sessione è attiva?] (Http://stackoverflow.com/questions/3788369/how-to-tell-if-a-session-is-active) - si prega di utilizzare la ricerca prima fare una domanda – hakre