There is speed/security difference Storing temporary Data in Files Vs Temporary table?
If I want to store a simple variable, I could do in a php file that will be included later, and, when not needed anymore, be deleted, or in a MySQL table with the MEMORY storage engine which is better?(and fastest?)
- Storing in a MySQL table with the MEMORY s开发者_JS百科torage engine.
- Storing in a "file.php" in some folder. (I create that file using php)
Storing info in memory will almost always be faster than writing to and reading from disk, often by orders of magnitude. As ChrisF said, you should always test a supposed optimization, but in principal you can expect memory to be faster.
There will also be less overhead than storing the data in a table. This can be good or bad - validating data types or maintaining uniqueness may be valuable to you, or it may be needless if your application is handling it. If there's a lot of data, then the querying and indexing capabilities of MySQL may be helpful.
One note - if you do create a temp file, I wouldn't use the .php extension. Depending on your host config, it may be readable to visitors by default. If it's genuinely temporary data, use a .tmp extension, and ensure that the folder is not publicly accessible.
精彩评论