jphilip Posted December 17, 2012 Share Posted December 17, 2012 (edited) 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/ Edited December 17, 2012 by jphilip Quote Link to comment https://forums.phpfreaks.com/topic/272100-php-apc-array-memory-issue/ Share on other sites More sharing options...
Christian F. Posted December 17, 2012 Share Posted December 17, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/272100-php-apc-array-memory-issue/#findComment-1399864 Share on other sites More sharing options...
jphilip Posted December 17, 2012 Author Share Posted December 17, 2012 well the readings are displayed using the 'apc.php' which comes with the apc .... both array and object are identical ... thats what puzzling ... I also tried generating 1000 values and reading it and object beat array always Quote Link to comment https://forums.phpfreaks.com/topic/272100-php-apc-array-memory-issue/#findComment-1399884 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.