views:

44

answers:

3

When I'm writing scripts in PHP to work with MySQL databases with a MEMORY storage engine, is it as fast as PHP variables? Can I consider using such a database in place of some variables for buffers, message queues, etc?

+1  A: 

No, it's not as fast as PHP variables because that is local to the web server. If you are accessing a MySQL MEMORY table it is in memory on the database server so you are accessing an external resource to get the information you need. There is also the additional time it takes to execute the queries against the table rather than execute local PHP code.

Taylor Leese
+1  A: 

Mysql will never be as fast as PHP variables, even if using a memory storage engine. You still have the overhead of the mysql client/server connection protocol, etc...

However, it should be fast enough for many cases where you have an advantage of using SQL for some datasets, for example.

Keeping that in mind, use it only when appropriate.

Also, you should look at memcached and (php extension) It doesn't support SQL, but it's a simple memory caching system with great features, and all your processes/servers can share the same cache

jcinacio
A: 

No


The protocols involve message passing and possible context switching; all are rather heavyweight ops.

DigitalRoss