$ _SESSION के अवरोध व्यवहार को ठीक करने का प्रयास करते समय मुझे इस समस्या का सामना करना पड़ा।
http://konrness.com/php5/how-to-prevent-blocking-php-requests/
सत्र फ़ाइल जब तक स्क्रिप्ट पूरा करता है या सत्र मैन्युअल बंद कर दिया है बंद कर दिया बनी हुई है।
तो, डिफ़ॉल्ट रूप से, एक पृष्ठ को केवल-पढ़ने के मोड में सत्र खोलना चाहिए। लेकिन एक बार यह केवल पढ़ने में खुला है, इसे लिखने के तरीके में बंद और फिर से खोलना होगा।
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
फिर जब आप कुछ मूल्य लिखने के लिए जाना:
WriteSessionValues(["username"=>$login_user]);
यदि कोई पुराना है तो नया सत्र शुरू न करें दौड रहा है? –
संभावित डुप्लिकेट [कैसे एक सत्र सक्रिय है या नहीं?] (Http://stackoverflow.com/questions/3788369/how-to-tell-if-a- सत्र-is-active) - कृपया पहले खोज का उपयोग करें एक सवाल पूछना – hakre