note 69630 deleted from function.session-start by tularis
| From: | tularis@php.net | Date: | Fri, 01 Nov 2013 09:55:59 +0000 |
| Subject: | note 69630 deleted from function.session-start by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-197378@lists.php.net to get a copy of this message | ||
Note Submitter: kyzer at 4u dot net
----
Recursive session usage isn't possible. By that I mean fetching (via curl or such) another page
on the site which uses sessions, as part of a page which itself uses sessions.
For example:
page1.php:
<?php
session_start();
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://example.com/backend.php");
curl_exec($curl);
?>
backend.php:
<?php
session_start();
print $_SESSION['foo'];
?>
In this case, requesting page1.php will hang the request indefinitely. backend.php is waiting to
open the session data for reading/writing, but it's still locked by page1.php, which is waiting
for backend.php to finish.
Because there's no session_end(), you can't get PHP to relinquish the lock on the session
data after session_start() has occured. The solution is just to include backend.php or its
functionality directly, e.g.:
require './backend.php';