What are the Advantage and Disadvantage of Caching in Web Development In PHP, how does it affect Database?

Asked by Declan McLaughlin on
5 Answers

Answer by Gabriela Glass

In-memory data caching can be one of the most effective strategies to improve your overall application performance and to reduce your database costs.,A database cache supplements your primary database by removing unnecessary pressure on it, typically in the form of frequently accessed read data. The cache itself can live in a number of areas including your database, application or as a standalone layer.,Many of the techniques we’ll review can be applied to any type of database. However, we’ll focus on relational databases as it’s the most common database caching use case.,Cache a subset of a fetched database row into a custom structure that can be consumed by your applications

Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
      Customer customer = new Customer();
and so on …

Source: https://aws.amazon.com/caching/database-caching/

Answer by Maximus Jacobs

There’s a lot of outdated information on the Web that leads new PHP users astray, propagating bad practices and insecure code. PHP: The Right Way is an easy-to-read, quick reference for PHP popular coding standards, links to authoritative tutorials around the Web and what the contributors consider to be best practices at the present time.,This is bad practice for all sorts of reasons, mainly that it’s hard to debug, hard to test, hard to read and it is going to output a lot of fields if you don’t put a limit on there.,Another option is to use the PHP Coding Standards Fixer. It will show which kind of errors the code structure had before it fixed them.,Right now PHP does not support Unicode at a low level. There are ways to ensure that UTF-8 strings are processed OK, but it’s not easy, and it requires digging in to almost all levels of the web app, from HTML to SQL to PHP. We’ll aim for a brief, practical summary.

> php -S localhost:8000

Source: https://phptherightway.com/

Answer by Damian Wells

This book presents a highly popular, easy, low-cost way to bring together the Web and databases to build applications. The most popular database management system used in these solutions is MySQL, a very fast and easy-to-use system distributed under an Open Source license by its manufacturer, MySQL AB. We discuss MySQL in detail in this book.,In any of these situations, a database server should be used to manage data:,Most of the services we enjoy on the Web are provided by web database applications. Web-based email, online shopping, forums and bulletin boards, corporate web sites, and sports and news portals are all database-driven. To build a modern web site, you need to develop a database application.,Get Web Database Applications with PHP and MySQL, 2nd Edition now with O’Reilly online learning.

GET /~hugh/index.html HTTP/1.1
Host: goanna.cs.rmit.edu.au
From: [email protected] (Hugh Williams)
User-agent: Hugh-fake-browser/version-1.0
Accept: text/plain, text/html
HTTP/1.1 200 OK
Date: Thu, 04 Dec 2003 04:30:02 GMT
Server: Apache/1.3.27 (Unix)
Last-Modified: Fri, 21 Nov 2003 22:26:07 GMT
ETag: "a87da0-2128-3fbe90ff"
Accept-Ranges: bytes
Content-Length: 8488
Content-Type: text/html

                          "-//W3C//DTD HTML 4.0 Transitional//EN"

Source: https://www.oreilly.com/library/view/web-database-applications/0596005431/ch01.html

Answer by Idris Alvarado

It is well connected with databases: PHP makes it easy to connect securely with almost any kind of database. This gives developers more freedom when choosing which database is best suited for the application being built.  ,Of course, some of the points we’ve listed above could be applied to other programming languages. So here are just a few of the main alternatives to PHP to help you choose which is best suited to your project or organization.,We spend most of our time here exploring the positive side of software development, nearshore and offshore team building, and how to run an awesome…,Interested in hiring talented Latin American developers to add capacity to your team? Contact Jobsity: the nearshore staff augmentation choice for U.S. companies.

PHP (Hypertext Preprocessor) is known as a general-purpose scripting language that can be used to develop dynamic and interactive websites. It was among the first server-side languages that could be embedded into HTML, making it easier to add functionality to web pages without needing to call external files for data. Its use has evolved over the years, with regular upgrades (version 8.0 was released in November 2020) adding features and unlocking new capabilities.

<!DOCTYPE html>

            echo "Hi, I'm a PHP script!";


Source: https://www.jobsity.com/blog/8-reasons-why-php-is-still-so-important-for-web-development

Answer by Jon Flores

Here is an example of this process with a shared cache proxy:,On the other hand, "private" indicates that the response is intended for a single user only and must not be stored by a shared cache. A private browser cache may store the response in this case.,RedBot, a tool to check your cache-related HTTP headers.,A cache will send the request to the origin server for validation before releasing a cached copy.

The cache should not store anything about the client request or server response. A request is sent to the server and a full response is downloaded each and every time.

Cache-Control: no-store

A cache will send the request to the origin server for validation before releasing a cached copy.

Cache-Control: no-cache

On the other hand, "private" indicates that the response is intended for a single user only and must not be stored by a shared cache. A private browser cache may store the response in this case.

Cache-Control: private
Cache-Control: public

For more details, see also the Freshness section below.

Cache-Control: max-age=31536000

When using the "must-revalidate" directive, the cache must verify the status of stale resources before using them. Expired resources should not be used. For more details, see the Validation section below. See the "Freshness" section below to see what we mean by "stale resources".

Cache-Control: must-revalidate

Source: https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching