Jump to content

Php Apc Array Memory Issue


jphilip

Recommended Posts

I am new and this is my first topic ...

 

I just wrote a script to test apc's performance ... I want to know whether storing arrays or objects in the apc makes any difference ... It turns out it does. I created a randomly generated array and object with the same values and then set it in the apc and it turns out arrays takes up 3 times more memory than object. Why is that ? If I serialize before setting in the apc then its not an issue ... but doesn't apc does serializing automatically ? I googled but could not find the answer

 

 

 

Here is the code

<?php

 

$exten = array();

$object = new stdClass();

 

for ($j=1; $j<=60; $j++) {

$key = 'var' . $j;

if ( $j <= 30 ){

$rand = rand (1 , 99999);

$exten['var' . $j] = $rand;

 

$object->$key = $rand;

 

} else {

$rand_str = generateRandomString(rand(5 , 50)); // function to create a random string between 5 and 50 bytes

$exten['var' . $j] = $rand_str;

$object->$key = $rand_str;

}

 

}

 

$size = strlen(serialize($exten));

echo "<br/>SIZE ARRAY => $size<br/>";

 

$size = strlen(serialize($object));

echo "<br/>SIZE OBJECT => $size<br/>";

 

apc_store('arrx',$exten);

apc_store('objx',$object);

 

echo 'end';

?>

 

 

Here is the screenshot of the array and object

http://www.flickr.co...N05/8281598320/

 

http://www.flickr.co...N05/8280543133/

Link to comment
https://forums.phpfreaks.com/topic/272100-php-apc-array-memory-issue/
Share on other sites

Your readings must be wrong, or missing something, for a very simple reason: Both images show an array.

Only difference is that in one of those pictures the array is wrapped inside a object of type stdClass. As far as I could spot, the array is identical too.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.