1--TEST--
2Test session_set_save_handler() function : test lazy_write
3--INI--
4session.use_strict_mode=0
5session.lazy_write=1
6session.save_path=
7session.name=PHPSESSID
8session.gc_probability=0
9session.save_handler=files
10--SKIPIF--
11<?php include('skipif.inc'); ?>
12--FILE--
13<?php
14
15ob_start();
16
17/*
18 * Prototype : bool session_set_save_handler(callback $open, callback $close, callback $read, callback $write, callback $destroy, callback $gc)
19 * Description : Sets user-level session storage functions
20 * Source code : ext/session/session.c
21 */
22
23echo "*** Testing session_set_save_handler() : test write short circuit ***\n";
24
25require_once "save_handler.inc";
26$path = dirname(__FILE__);
27session_save_path($path);
28session_set_save_handler("open", "close", "read", "write", "destroy", "gc", "create_sid", "validate_sid", "update");
29
30session_start();
31$session_id = session_id();
32$_SESSION["Blah"] = "Hello World!";
33$_SESSION["Foo"] = FALSE;
34$_SESSION["Guff"] = 1234567890;
35var_dump($_SESSION);
36
37session_write_close();
38session_unset();
39var_dump($_SESSION);
40
41echo "Starting session again..!\n";
42session_id($session_id);
43session_set_save_handler("open", "close", "read", "write", "destroy", "gc", "create_sid", "validate_sid", "update");
44session_start();
45var_dump($_SESSION);
46$_SESSION['Bar'] = 'Foo';
47session_write_close();
48
49echo "Starting session again..!\n";
50session_id($session_id);
51session_set_save_handler("open", "close", "read", "write", "destroy", "gc", "create_sid", "validate_sid", "update");
52session_start();
53var_dump($_SESSION);
54// $_SESSION should be the same and should skip write()
55session_write_close();
56
57echo "Cleanup\n";
58session_start();
59session_destroy();
60
61ob_end_flush();
62?>
63--EXPECTF--
64*** Testing session_set_save_handler() : test write short circuit ***
65Open [%s,PHPSESSID]
66CreateID [PHPT-%s]
67Read [%s,%s]
68array(3) {
69  ["Blah"]=>
70  string(12) "Hello World!"
71  ["Foo"]=>
72  bool(false)
73  ["Guff"]=>
74  int(1234567890)
75}
76Write [%s,%s,Blah|s:12:"Hello World!";Foo|b:0;Guff|i:1234567890;]
77Close [%s,PHPSESSID]
78array(3) {
79  ["Blah"]=>
80  string(12) "Hello World!"
81  ["Foo"]=>
82  bool(false)
83  ["Guff"]=>
84  int(1234567890)
85}
86Starting session again..!
87Open [%s,PHPSESSID]
88Read [%s,%s]
89array(3) {
90  ["Blah"]=>
91  string(12) "Hello World!"
92  ["Foo"]=>
93  bool(false)
94  ["Guff"]=>
95  int(1234567890)
96}
97Write [%s,%s,Blah|s:12:"Hello World!";Foo|b:0;Guff|i:1234567890;Bar|s:3:"Foo";]
98Close [%s,PHPSESSID]
99Starting session again..!
100Open [%s,PHPSESSID]
101Read [%s,%s]
102array(4) {
103  ["Blah"]=>
104  string(12) "Hello World!"
105  ["Foo"]=>
106  bool(false)
107  ["Guff"]=>
108  int(1234567890)
109  ["Bar"]=>
110  string(3) "Foo"
111}
112Update [%s,PHPT-%d]
113Close [%s,PHPSESSID]
114Cleanup
115Open [%s,PHPSESSID]
116Read [%s,PHPT-%d]
117Destroy [%s,PHPT-%d]
118Close [%s,PHPSESSID]
119