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
php object in memory
Moderator: General Moderators
Re: php object in memory
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.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: php object in memory
It is is a single server application, then you can also use APC cache.
(#10850)
-
adamSpline
- Forum Newbie
- Posts: 11
- Joined: Fri Sep 16, 2011 1:30 pm
Re: php object in memory
Hi all,
Thanks for the reply. I will look into both solutions. At this point it is a single server app.
-Adam
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
MySQL also has a MEMORY storage engine. You'll still be hitting the MySQL daemon, but won't be hitting the disk.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: php object in memory
Which is where most of the delays arepickle wrote:You'll still be hitting the MySQL daemon, but won't be hitting the disk.
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.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: php object in memory
APC is definitely a requirement in any development as an opcode cache. As a typical key store, memcached is much faster as APC.Christopher wrote:It is is a single server application, then you can also use APC cache.