
Originally Posted by
K. Wolfe
More thoughts: What version of PHP are you running. Do you have garbage collection enabled? When you are manipulating the json / arrays, are you duplicating the arrays out that might cause some extra memory usage?
Code PHP:
$bigArray = array(); //your return result from remote server
$object2 = $bigArray()
Obviously your not using arrays or just going to straight up copy an object like that, but you may be altering it in some way and moving that altered object to a new variable, if that makes sense.
That's actually a really good question, at first I thought maybe arrays would assume by reference in assignment (they don't -- unlike other languages).
PHP Code:
$smallArray = array(1, 2, 3, 4, 5, 6, 7);
$newArray = $smallArray;
array_pop($smallArray);
var_dump($smallArray, $newArray);
Output
Code:
array(6) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
[3]=>
int(4)
[4]=>
int(5)
[5]=>
int(6)
}
array(7) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
[3]=>
int(4)
[4]=>
int(5)
[5]=>
int(6)
[6]=>
int(7)
}
However, forcing by reference
PHP Code:
$smallArray = array(1, 2, 3, 4, 5, 6, 7);
$newArray = &$smallArray;
array_pop($smallArray);
var_dump($smallArray, $newArray);
Output
Code:
array(6) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
[3]=>
int(4)
[4]=>
int(5)
[5]=>
int(6)
}
array(6) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
[3]=>
int(4)
[4]=>
int(5)
[5]=>
int(6)
}
Bookmarks