hiphop-php /hphp/test/slow/apc_objects.php

Language PHP Lines 164
MD5 Hash 7cd990b3473e8d96b5a965751d8d422b Estimated Cost $3,326 (why?)
Repository git://github.com/facebook/hiphop-php.git View Raw File View Project SPDX
  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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?hh

$s = strtolower('heLLo');

class C {
  public $x = 3;
  public $f = 'hi';
}

class B {
  public $f;
}

function apcOps($key, $val) {
  apc_store($key, $val);
  // need to fetch the value twice because under common
  // config settings object are serialized on first store
  // and APCObject (APCCollection) are created on second
  // fetch
  var_dump(apc_fetch($key));
  var_dump(apc_fetch($key));
}

echo "**** Object instance with simple properties\n";
$o = new C;
apcOps('key', $o);

echo "**** Vector containing object reference\n";
$c = Vector{1, 2, $o};
apcOps('key', $c);
echo "modify previous instance from APC\n";
$apcObj = apc_fetch('key');
$apcObj[] = 'hi';
$apcObj[0] = 100;
$opcObj = null;
var_dump('MUTATED', $apcObj);
var_dump(apc_fetch('key'));

echo "**** Vector containing non-refcounted values\n";
$c = Vector{1, 'hello'};
apcOps('key', $c);
echo "modify previous instance from APC\n";
$apcObj = apc_fetch('key');
$apcObj[] = 'hi';
$apcObj[0] = 100;
$opcObj = null;
var_dump('MUTATED', $apcObj);
var_dump(apc_fetch('key'));

echo "**** Vector containing simple values\n";
$c = Vector{true, $s};
apcOps('key', $c);
echo "modify previous instance from APC\n";
$apcObj = apc_fetch('key');
$apcObj[] = 'hi';
$apcObj[0] = 100;
$opcObj = null;
var_dump('MUTATED', $apcObj);
var_dump(apc_fetch('key'));

echo "**** Map containing non-refcounted values\n";
$m = Map{'a' => 'b', 'c' => 'd'};
apcOps('key', $m);
echo "modify previous instance from APC\n";
$apcObj = apc_fetch('key');
$apcObj['one'] = 'hi';
$apcObj['a'] = 100;
$opcObj = null;
var_dump('MUTATED', $apcObj);
var_dump(apc_fetch('key'));

echo "**** Map containing itself\n";
$m = Map{'a' => 'b', 'c' => $m};
apcOps('key', $m);
echo "modify previous instance from APC\n";
$apcObj = apc_fetch('key');
$apcObj['one'] = 'hi';
$apcObj['a'] = 100;
$opcObj = null;
var_dump('MUTATED', $apcObj);
var_dump(apc_fetch('key'));

echo "**** Map containing a vector\n";
$m = Map{'a' => 'b', 'c' => $c};
apcOps('key', $m);
echo "modify previous instance from APC\n";
$apcObj = apc_fetch('key');
$apcObj['one'] = 'hi';
$apcObj['a'] = 100;
$opcObj = null;
var_dump('MUTATED', $apcObj);
var_dump(apc_fetch('key'));

echo "**** Immutable Vector instance\n";
$c = ImmVector{1, 'hello'};
apcOps('key', $c);

echo "**** Immutable Map instance\n";
$m = ImmMap{'a' => 'b', 'c' => 'd'};
apcOps('key', $m);

echo "**** Object instance containg itself\n";
$o = new C;
$o->x = $o;
apcOps('key', $o);

echo "**** Object instance containg itself 2\n";
$o = new C;
$o->x = new B;
$o->x->f = $o;
apcOps('key', $o);

echo "**** Object instance containg itself 3\n";
$o = new C;
$o->x = new B;
$o->x->f = Vector{};
$o->x->f[] = $o;
apcOps('key', $o);

echo "**** Object instance containg itself 4\n";
$o = new C;
$o->x = new B;
$o->x->f = Vector{};
$o->x->f[] = $o->x;
apcOps('key', $o);

echo "**** Object instance containg itself 5\n";
$o = new C;
$o->x = new B;
$o->x->f = Vector{};
$o->x->f[] = new B;
apcOps('key', $o);

echo "**** Object instance containg Vector instace with simple values\n";
$o = new C;
$o->x = new B;
$o->x->f = Vector{};
$o->x->f[] = 10;
$o->x->f[] = 'hi';
$o->x->f[] = strtolower('heLLo');
apcOps('key', $o);

echo "**** Object instance containg collections instaces\n";
$o = new C;
$o->x = new B;
$o->x->f = Map{};
$o->x->f['k'] = 10;
$o->x->f['k1'] = 'hi';
$o->x->f['k2'] = Vector{};
$o->x->f['k2'][] = 100;
$o->x->f['k2'][] = 'hello';
apcOps('key', $o);

echo "**** Set instance\n";
$s = Set{ 1, 'hi', 4, $s};
apcOps('key', $s);

echo "**** Set instance with int-like strings\n";
$s = Set{ 123, '123'};
apcOps('key', $s);

echo "**** Make sure delete is ok\n";
apc_delete('key');
Back to Top