1--TEST--
2Test session_set_save_handler() : full handler implementation
3--INI--
4session.save_handler=files
5session.name=PHPSESSID
6--SKIPIF--
7<?php include('skipif.inc'); ?>
8--FILE--
9<?php
10
11ob_start();
12
13echo "*** Testing session_set_save_handler() : full handler implementation ***\n";
14
15class MySession2 extends SessionHandler {
16    public $path;
17
18    public function open($path, $name) {
19        if (!$path) {
20            $path = sys_get_temp_dir();
21        }
22        $this->path = $path . '/u_sess_' . $name;
23        return true;
24    }
25
26    public function close() {
27        return true;
28    }
29
30    public function read($id) {
31        return (string)@file_get_contents($this->path . $id);
32    }
33
34    public function write($id, $data) {
35        return (bool)file_put_contents($this->path . $id, $data);
36    }
37
38    public function destroy($id) {
39        @unlink($this->path . $id);
40        return true;
41    }
42
43    public function gc($maxlifetime) {
44        foreach (glob($this->path . '*') as $filename) {
45            if (filemtime($filename) + $maxlifetime < time()) {
46                @unlink($filename);
47            }
48        }
49        return true;
50    }
51}
52
53$handler = new MySession2;
54session_set_save_handler(array($handler, 'open'), array($handler, 'close'),
55    array($handler, 'read'), array($handler, 'write'), array($handler, 'destroy'), array($handler, 'gc'));
56session_start();
57
58$_SESSION['foo'] = "hello";
59
60var_dump(session_id(), ini_get('session.save_handler'), $_SESSION);
61
62session_write_close();
63session_unset();
64
65session_start();
66var_dump($_SESSION);
67
68session_write_close();
69session_unset();
70
71session_set_save_handler($handler);
72session_start();
73
74$_SESSION['foo'] = "hello";
75
76var_dump(session_id(), ini_get('session.save_handler'), $_SESSION);
77
78session_write_close();
79session_unset();
80
81session_start();
82var_dump($_SESSION);
83
84session_write_close();
85session_unset();
86?>
87--EXPECTF--
88*** Testing session_set_save_handler() : full handler implementation ***
89string(%d) "%s"
90string(4) "user"
91array(1) {
92  ["foo"]=>
93  string(5) "hello"
94}
95array(1) {
96  ["foo"]=>
97  string(5) "hello"
98}
99string(%d) "%s"
100string(4) "user"
101array(1) {
102  ["foo"]=>
103  string(5) "hello"
104}
105array(1) {
106  ["foo"]=>
107  string(5) "hello"
108}
109