Ask your Symfony questions! Pay money and get answers fast! (more info)

MemCache errors with Symfony Symfony

  • SOLVED

Has anyone used MemCache with Symfony?

I run a simple query:

$c = new Criteria();
$c->add(GreenwichPeer::TEXTID, $id);
$c->add(GreenwichPeer::STATE, 'W');
$v = GreenwichPeer::doSelectOne($c, $con);


and I get a MemCache error:

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 4 bytes) in /home/lib/MEMCACHELocalCache.class.php on line 85


Our MemCache class is a simple wrapper around the MemCache class you can find on php.net.

public function Set( $key, $var, $expires=0 )
{

if( $expires < 0 ) return;
if( ! $expires ) $expires = $this->ttl;

//$exptime = time() + ($expires * 60 );
$exptime = ($expires * 60 );

// Set the cache
$key = SF_PRODUCT.'_'.strtoupper($key);

if( ! $this->cache->set( $key, $var, false, $exptime ) )
GeneralLogger::Write('LOCALMEMORYCACHE','Unable to set memcache key/value');

}

public function Get( $key )
{
$key = SF_PRODUCT.'_'.strtoupper($key);
return ( $this->cache->get( $key ) );
}



Anyone else have a problem like this?

I also tried the query like this:

$criteria0 = new Criteria();
$criteria0->add(CaoContentPeer::TEXTID, $id);
$criteria1 = $c->newCriterian(CaoContentPeer::STATE, 'W');
$criteria0->addAnd($criteria1);
$v = CaoContentPeer::doSelectOne($criteria0, $con);




Same problem.

Answers (7)

2010-04-28

casivaagustin answers:

open your php.ini

look for
memory_limit = 8M

change this to

memory_limit = 16M

You'll find that a few things are memory intensive, rather than processor intensive. Increasing the limit and restart apache will fix this.

Note: You need to restart Apache after making any changes to php.ini.


casivaagustin comments:

open php.ini

look for
memory_limit = 8M

change this to

memory_limit = 16M

16 or More if is needed

You'll find that a few things are memory intensive, rather than processor intensive. Increasing the limit and restart apache will fix this.

Note: You need to restart Apache after making any changes to php.ini.


casivaagustin comments:

open your php.ini

look for
memory_limit = 8M

change this to

memory_limit = 16M

16 or More if yo Needed.

You'll find that a few things are memory intensive, rather than processor intensive. Increasing the limit and restart apache will fix this.

Note: You need to restart Apache after making any changes to php.ini.

2010-04-28

Arturo Linares answers:

If you still have memory problems and you are using php 5.1 there is a bug where recursive references leaks memory:

http://bugs.php.net/bug.php?id=33595

It was fixed in PHP 5.3


marshall comments:

Thanks. This was a big part of it.

2010-04-28

Eduardo Raffoul answers:

Usually this kind of errors are related to your server configuration. You should look for php.ini (the path depends on your sever installation, if you're using lamp, xampp, mamp, etc..)

Inside php.ini look for:
memory_limit = ...

change the value for:
memory_limit = 32M

and that should solve your problem

PS1: You usually need root grant access to change this.
PS2: You must restart your server for the new configuration to take effect

2010-04-28

Bill Hunt answers:

The other posters are right, this doesn't have anything to do with Memcache; that runs outside of PHP. However, I would advise caution before increasing your memory limit willy-nilly; you probably should be debugging your query to find out why it's exceeding 8MB on a selectOne(), as you don't want to choke the server.

2010-04-28

Martin Palacio answers:

What is exactly the line #85?

How many records do you have in Greenwich table? Did you set the correct indexes?

Try to deactivate MemCache. How long takes the query (SQL) to execute?

2010-04-28

Ender Technology answers:

It initially appears that the database row contains almost 32MB of data. However, we need more information regarding your setup such as how the caching layer is integrated.

Do you use the sfPropelMemcachePlugin? My other guess is that somewhere in that caching layer is attempting to retrieve/stuff almost 32MB of data.

While investigating I recommend following "mppfiles" suggestion from above to reduce the number of variables in this situation.

Rob O.
Ender Tech Corp.
[[LINK href="http://www.endertech.com"]]www.endertech.com[[/LINK]]

2010-04-29

Aleksander Wons answers:

I have faced similar problem when i passed sfContext object around the app.
If You will try to serialize or unserialize sfContext object You will almost always runt into such problem.

Additionally there is not enough background to figure out why this is happening. Symfony should not use more then 16MB per instance unless You are something that consumes Your memory.

It is difficult to help when we have insufficient details.