1--TEST-- 2Test session_set_save_handler() : manual shutdown 3--INI-- 4session.save_handler=files 5session.name=PHPSESSID 6--EXTENSIONS-- 7session 8--FILE-- 9<?php 10 11ob_start(); 12 13echo "*** Testing session_set_save_handler() : manual shutdown ***\n"; 14 15class MySession extends SessionHandler { 16 public $num; 17 public function __construct($num) { 18 $this->num = $num; 19 echo "(#$this->num) constructor called\n"; 20 } 21 public function __destruct() { 22 echo "(#$this->num) destructor called\n"; 23 } 24 public function finish() { 25 $id = session_id(); 26 echo "(#$this->num) finish called $id\n"; 27 session_write_close(); 28 } 29 public function write($id, $data): bool { 30 echo "(#$this->num) writing $id = $data\n"; 31 return parent::write($id, $data); 32 } 33 public function close(): bool { 34 $id = session_id(); 35 echo "(#$this->num) closing $id\n"; 36 return parent::close(); 37 } 38} 39 40$handler = new MySession(1); 41session_set_save_handler($handler); 42session_start(); 43 44$_SESSION['foo'] = 'bar'; 45 46// explicit close 47$handler->finish(); 48 49echo "done\n"; 50ob_end_flush(); 51?> 52--EXPECTF-- 53*** Testing session_set_save_handler() : manual shutdown *** 54(#1) constructor called 55(#1) finish called %s 56(#1) writing %s = foo|s:3:"bar"; 57(#1) closing %s 58done 59(#1) destructor called 60