Bug #72265 [Fbk->Csd]: session exception
Edit report at https://bugs.php.net/bug.php?id=72265&edit=1
ID: 72265
User updated by: wangyuan at lianlife dot com
Reported by: wangyuan at lianlife dot com
Summary: session exception
-Status: Feedback
+Status: Closed
Type: Bug
Package: Session related
Operating System: linux 5.4 x64
PHP Version: 5.6.21
Block user comment: N
Private report: N
New Comment:
Thank you very much.
try {
session_set_save_handler($handler, false);
session_start();
.....
session_write_close(); // <- close the session manually, I can catch the exception in catch
block
.....
} catch (Exception $e) {
print_r($e);
}
Previous Comments:
------------------------------------------------------------------------
[2016-05-26 03:25:40] requinix@php.net
I see the read exception being caught fine. With that commented out, the write exception cannot be
caught normally because that happens at script shutdown - outside the try/catch block. If I close
the session manually with session_write_close() at the end of the try block then the write exception
gets caught as expected.
Does that match what you are seeing?
------------------------------------------------------------------------
[2016-05-26 02:37:23] wangyuan at lianlife dot com
Description:
------------
I can't catch the exception that is thrown from the write method in the sess class, but other
methods can work properly, such as open (), read () and other.
I'm not sure PHP itself is designed, or is it a bug.
Run result in the console :
Test script:
---------------
class sess extends SessionHandler {
public function read($session_id) {
throw new Exception('read');
}
public function write($session_id, $session_data) {
throw new Exception('write');
}
}
try {
$handler = new sess();
session_set_save_handler($handler, true);
session_start();
$_SESSION['name'] = 'php';
$_SESSION['gender'] = 'female';
echo $_SESSION['name'];
} catch (Exception $e) {
echo '<pre>';
print_r($e);
echo '</pre>';
}
Expected result:
----------------
The following information should be catch, but it is displayed as "excetpion Uncaught"
2016/05/26 10:17:37 [error] 13474#0: *19551 FastCGI sent in stderr: "PHP message: PHP Fatal
error: Uncaught exception 'Exception' with message
'0jib891huoct6e4lpl5i3f9tt7name|s:8:"wangyuan";gender|s:4:"male";' in
/data/web/ndl/test.php:11
Stack trace:
#0 [internal function]: sess->write('0jib891huoct6e4...',
'name|s:8:"wangy...')
#1 [internal function]: session_write_close()
#2 {main}
thrown in /data/web/ndl/test.php on line 11" while reading response header from upstream,
client: 10.24.18.243, server: ndl.lianlife.com, request: "GET /test.php HTTP/1.1",
upstream: "fastcgi://127.0.0.1:9000", host: "10.20.33.33:81"
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72265&edit=1
Thread (4 messages)