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/

Edited by jphilip
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.