-
Notifications
You must be signed in to change notification settings - Fork 21
/
pearbug19422.phpt
132 lines (109 loc) · 2.91 KB
/
pearbug19422.phpt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
--TEST--
Cache_Lite::Cache_Lite (PEAR bug #19422)
--INI--
track_errors=Off
--FILE--
<?php
/**
* Test for Pear Bug #19422
*
* @see https://pear.php.net/bugs/bug.php?id=19422
* @see https://bugs.php.net/bug.php?id=30936
*
* @package Cache_Lite
* @category Caching
* @author Markus Tacker <tacker@php.net>
*/
require_once __DIR__ . '/bootstrap.php';
require_once __DIR__ . '/../Cache/Lite.php';
define('FsStreamWrapper_CACHE_DIR', sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'cachelite-streamwrapper' . DIRECTORY_SEPARATOR);
class FsStreamWrapper
{
const SCHEME = 'public';
private $fp;
public function __construct()
{
if (!is_dir(FsStreamWrapper_CACHE_DIR)) mkdir(FsStreamWrapper_CACHE_DIR);
}
public function url_stat($path, $flags)
{
$localpath = $this->scheme2file($path);
if (!is_file($localpath)) return 0;
return stat($localpath);
}
private function scheme2file($path)
{
return str_replace(self::SCHEME . '://', FsStreamWrapper_CACHE_DIR, $path);
}
public function stream_open($path, $mode, $options, &$opath)
{
$this->fp = fopen($this->scheme2file($path), $mode);
return true;
}
public function stream_write($data)
{
return fwrite($this->fp, $data);
}
public function stream_close()
{
return fclose($this->fp);
}
public function stream_lock($operation)
{
return flock($this->fp, $operation);
}
public function unlink($path)
{
return unlink($this->scheme2file($path));
}
public function stream_read($count)
{
return fread($this->fp, $count);
}
public function stream_eof()
{
return feof($this->fp);
}
public function stream_seek($offset, $whence)
{
return !fseek($this->fp, $offset, $whence);
}
public function stream_flush()
{
return fflush($this->fp);
}
public function stream_tell()
{
return ftell($this->fp);
}
public function rename($from_uri, $to_uri)
{
return rename($this->scheme2file($from_uri), $this->scheme2file($to_uri));
}
}
$xml = array();
$cacheOpt = array();
$cacheOpt['cacheDir'] = 'public://';
$cacheOpt['cache_time'] = 3600;
$Cache_Lite = new Cache_Lite($cacheOpt);
$Cache_Lite->setToDebug();
stream_wrapper_register(FsStreamWrapper::SCHEME, 'FsStreamWrapper');
$fp = fopen('/dev/urandom', 'r');
$data = fread($fp, 32 * 1024);
fclose($fp);
$Cache_Lite->save($data, 'largechache');
$verify = $Cache_Lite->get('largechache');
var_export(strlen($data) === strlen($verify)); echo "\n";
var_export($data === $verify); echo "\n";
?>
--CLEAN--
<?php
define('FsStreamWrapper_CACHE_DIR', sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'cachelite-streamwrapper' . DIRECTORY_SEPARATOR);
foreach(glob(FsStreamWrapper_CACHE_DIR . 'cache*') as $file) {
unlink($file);
}
@rmdir(FsStreamWrapper_CACHE_DIR);
?>
--EXPECT--
true
true