Home Backend Development PHP Tutorial 18 critical mistakes to pay attention to in web development

18 critical mistakes to pay attention to in web development

Nov 11, 2016 pm 03:31 PM
php

In the past few years, I had the opportunity to participate in some interesting projects and independently complete development, upgrades, refactoring, and development of new features.

This article summarizes some key mistakes that PHP programmers often overlook in web development, especially when dealing with medium and large projects. Typical errors include the inability to distinguish between various development environments and the failure to use cache and backup.

The following uses PHP as an example, but its core ideas are applicable to every web programmer.

Application level errors

1. Error reporting is turned off during the development stage

  The only thing I want to ask is: Why? Why should you turn off error reporting while developing?

PHP has many levels of error reporting, and we must turn them all on during the development phase.

If you think errors will not happen, then you are idealizing the program. In the real world, errors are inevitable. error_reporting and display_error are two completely different methods. error_reporting () sets the error level, while display_errors sets whether error information should be output.

During the development phase, the error reporting level should be set to the highest level, such as the following settings: error_reporting (E_ALL); and ini_set ('display_errors', true);

Contrary to the previous point, many programmers like to drown errors. You know that errors will happen, but you choose to hide them, and then you can go home early and sleep. Little did they know that more serious mistakes would occur in the future.

3. There is no usage log anywhere in the code

You must keep the usage log in mind at the beginning of software development. You cannot make up for the logging function until the end of the project. . Many programmers will use one method or another to record logs, but few people can actually use logs to record abnormal information. What is the use of a log system that no one checks?

4. No cache is used

In the application system, we can use cache at multiple system levels, such as on the server side, application side and database side. wait. Like logging, caching should be applied to the system from the beginning. You can disable caching during development and enable caching after product release.

5. Abandoning best practices and design patterns

How many people have you seen using their own password encryption algorithms? Sorry to tell you, there are a lot of them because they think they will know better about it.

The best practices and design patterns have been created by predecessors. This is often easier and more effective than reinventing the wheel yourself. We developers only need to be proficient in these design patterns and use them reasonably. Just apply it in the project, such as some encryption algorithms.

6. No automated testing is used

Tests are used in every Web project, just like logs. If no one manages and uses them, so will the tests. Useless.

Running a test project is a tedious task. Fortunately, there are a series of tools to help us achieve automated testing. In PHP development, there is a good testing tool called Jenkins, which is very convenient to use.

7. No code review

Working in a team is a very big challenge, because each member has his own different working habits and methods. Without good specifications, project development will take many detours.

Every member of the team should review each other's code, just like unit tests, which can help the project become cleaner and more consistent.

8. Programming only considers ideal situations

Have you ever encountered problems or even chaos in your own or other people’s code after it was handed over to the customer? Of course I didn't.

This situation often occurs because developers are lazy and only consider ideal situations, which can lead to database crashes, PHP fatal errors, or even servers being hacked. When writing code, programmers must not only consider the best case scenario, but also the worst case scenario. Only by thinking comprehensively can the code cover all situations.

9. Failure to correctly apply object-oriented programming ideas

Most PHP beginners will not use object-oriented ideas in their code, because this concept is It was difficult to understand at the beginning

Of course, the concept of object-oriented is not simply to organize some classes together

Objects, properties, methods, inheritance and encapsulation, etc. These are the most basic concepts in OOP. After developers correctly use the object-oriented design pattern, they will be able to write cleaner and more scalable code.

10. "On-the-fly" programming

Most developers will encounter this situation: "Quick, the customer needs a "New functions must be able to run ASAP", so you add some new functions to the source code, and then upload them directly to the running server. We call this programming method "On-the-fly" programming.

When we develop software, especially medium and large projects, we must analyze, program and release according to the workflow, which will greatly reduce future software bugs. This "flight mode" is not advisable.

Database-level errors

11. Failure to separate database reading and writing

In order to run a complex system for a long time, each Programmers should consider the scalability of the system. 99% of the time, the system does not need to consider expansion because there is not such a large amount of traffic.

Why do we need to separate database reading and writing?

In every system, the database will be the first bottleneck to appear. Under the impact of large traffic, the database is likely to be the first to die. So in most cases we use multiple databases to spread the traffic, and developers often use Master-Slave mode or Master-Master mode. Master-Slave is the most popular database pressure sharing mode. It will route the specified select statement to each Slave server, which will reduce the pressure on the Master server a lot.

12. The code can only connect to one database

This is very similar to the previous error, but developers sometimes need to connect to multiple databases for some reasons. , for example, you will put high-load data such as user logs, activity information streams, and real-time data analysis into different databases to relieve the pressure on the main database.

13. Failure to detect database vulnerabilities

If you do not detect vulnerabilities in the database, it is equivalent to opening the server's door to most hackers.

Among the many vulnerabilities, database vulnerabilities are the most vulnerable, and the most common one is SQL injection. Therefore, it is still necessary to conduct database vulnerability detection regularly.

14. Data tables do not have indexes

Indexes play a very important role in data tables. Appropriate indexes can improve the performance of each table. Here is an article The article tells how to create an index and when to create an index.

15. No transaction mechanism is used

Data integrity is very important to the Web system. If an error occurs in data consistency, the entire system will collapse and be difficult to repair. Proper use of the database transaction mechanism will effectively solve this problem. For example, if you want to save user data, there are e-mail, username and password in table1, and first name, last name, and gender age in table2. We can use transactions to ensure that the data is updated at the same time or not at the same time when updating two tables.

16. Sensitive data is not encrypted

 

  PHP5.5 provides a hash encryption method, which is used as follows:  

$hash = password_hash ( $password, PASSWORD_BCRYPT );

 17. No backup

Did you see the picture below? If you encounter such a situation and you don’t have a backup, everything will be over.

 101552ivbihjjklhkuuuyy.jpg

18. No monitoring

Without monitoring, you will not know what will happen next What happens? For monitoring, you should pay attention to the following questions:

•How many people can directly access this application service?

•Is the server running under high load?

•Do we need to expand the system with another database server?

•Where are the failure points of the application system?

•Is the system currently offline?


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1662
14
PHP Tutorial
1261
29
C# Tutorial
1234
24
How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

See all articles