In Web applications, a large amount of static data should be stored in the database or stored directly in the PHP business layer

Source: Internet
Author: User
Tags mysql update
In a Web application, should a large amount of static data be stored in a database or stored directly in the PHP business layer?
This means that a Web application with a large amount of static data, such as a MYSQL-PHP-JS-architecture web game, has a large amount of relatively static data, such as the number of experiences per liter, such as each city, the parameters of each prop, and so on. This data is usually changed only when the version is updated.

If stored in a database (read-only table), then each business needs to query one or more of these static data tables.
If the PHP business layer is stored directly as an associative array (PHP code automatically generated from Excel's schema table schemas), then defining and manipulating the large associative array may also affect the efficiency of the server PHP file execution.

In contrast, which of the above two options is more efficient? It's the equivalent of putting pressure on the MySQL layer or the PHP layer, which is easier.

If you feel that I have not stated clearly, I will add the instructions.
------to solve the idea----------------------
Like what one level per literHow much experience is needed, such as each city, the parameters of each prop, etc.
If the upgrade is done by PHP code, it doesn't matter what you save
If the upgrade is done by a SQL script, then of course it is saved as a table for the background implementation

------to solve the idea----------------------
Personally I think you are a bit like the system configuration information. A lot of suggestions in the database, put it in the cache for easy reading
------to solve the idea----------------------
Why do I have to choose two and use it together?
Data source is placed in MySQL, maintenance is also directly update the data in the library
Then write a program to cache each set of static data into a PHP script file, for example: Upgrade experience. data.php: 1, 2=> 2) ...
When data is needed, upgrade experience = Include ' upgrade experience. data.php ';
Save in multiple files, use whichever to read, avoid a lot of statements
When the data is updated, the data in MySQL is changed, the cache file is deleted and re-run the program generates.

------to solve the idea----------------------
Personal feelings can be stored in databases and Redis,

Generally get from Redis, if Redis has no value go to MySQL to get

MySQL value is set by PHP

Just maintain MySQL and Redis synchronization (such as MySQL restart update redis,mysql update also update Redis)

This is good maintenance, also can directly put in memory, maintenance and access speed is no problem

The same second floor, not recommended to put PHP code, this is the most bad way ... If you really want to, then define in a public file ...

Landlord's own choice
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.