Page 1 of 1

php object in memory

Posted: Fri Sep 16, 2011 1:38 pm
by adamSpline
Hi all,

I am new to this form, and to php. I am creating an app that will have lots of frequent (but small) requests coming into the server. I would like to keep some of the data in memory on the server so I do not need to constantly thrash the database.

In java this was pretty easy. I would just create a singleton static object that is shared among any given jsp/servlet. I would put data in that object which needs to be updated and accessed frequently.

I am new to php, but I have not found a straightforward way to do this. Any ideas?

Thanks,

-Adam

Re: php object in memory

Posted: Fri Sep 16, 2011 1:54 pm
by greip
Have a look at the Memcached library: http://www.php.net/manual/en/book.memcached.php Using memcached you can persist values in an in-memory database shared between all php-interpreters serving requests for you application.

Re: php object in memory

Posted: Fri Sep 16, 2011 5:51 pm
by Christopher
It is is a single server application, then you can also use APC cache.

Re: php object in memory

Posted: Sat Sep 17, 2011 11:19 pm
by adamSpline
Hi all,

Thanks for the reply. I will look into both solutions. At this point it is a single server app.

-Adam

Re: php object in memory

Posted: Tue Sep 20, 2011 4:47 pm
by pickle
MySQL also has a MEMORY storage engine. You'll still be hitting the MySQL daemon, but won't be hitting the disk.

Re: php object in memory

Posted: Tue Sep 20, 2011 5:08 pm
by John Cartwright
pickle wrote:You'll still be hitting the MySQL daemon, but won't be hitting the disk.
Which is where most of the delays are :D

I would definitely use memcache for any temporary data that can easily be queried, i.e., by a key. Anything that involves any querying complexity use MySQL memory tables.

Re: php object in memory

Posted: Tue Sep 20, 2011 5:15 pm
by John Cartwright
Christopher wrote:It is is a single server application, then you can also use APC cache.
APC is definitely a requirement in any development as an opcode cache. As a typical key store, memcached is much faster as APC.