Home >Backend Development >PHP Tutorial >Development principles of top PHP masters_PHP tutorial
1. Use PHP when appropriate – Rasmus Lerdorf
No one understands where PHP is more reasonable than the creator of PHP, Rasmus Lerdorf. He released the PHP language in 1995. Since then, PHP has been like a prairie fire, burning all over the world. The development camp has changed the world of the Internet. However, Rasmus did not create PHP for this reason. PHP was born to solve practical problems of web developers.
Like many open source projects, PHP has become popular. The motivation for its popularity cannot be explained by normal philosophy, and it is even so popular that it is somewhat self-admiring. It can be used as a case, a case caused by the need for tools to solve various Web problems. Therefore, when PHP first appeared, all such tool needs were focused on PHP.
However, you can’t expect PHP to solve all problems. Lerdorf is the first to admit that PHP is just a tool, and there are many situations where PHP is beyond its capabilities.
Choose the right tool according to the job. I have gone to many companies to convince them to deploy and use PHP, but this does not mean that PHP is suitable for every problem. It is just a front-end scripting language that can solve most problems.
As a web developer, trying to solve all problems with PHP is unscientific and will waste your time. When PHP doesn't work, don't hesitate to try other languages.
2. Use multi-table storage to improve scalability – Matt Mullenweg
No one wants to question Matt Mullenweg’s authority in PHP. He developed the most popular blogging system on the planet (supported by a strong community): WordPress. After creating WordPress, Matt and his team launched The WordPress.com platform is a free blog site based on WordPress MU. Today, WordPress.com has approximately 4 million users, who contribute more than 140,000 posts every day. (To see more WordPress.com statistics, click here.)
If anyone knows how to make a website scale easily, it’s Matt Mullenweg. In 2006, Matt made forward-looking improvements to WordPress's data structure and explained why WordPress MU uses independent MYSQL tables for each blog instead of stuffing all blog data into one huge table.
We tested this approach, but found that scaling it out would be too expensive. If you use an overall data structure, you will face server hardware problems in the face of large traffic. Inside MU. Users are distributed into separate tables and can be easily organized. For example, WordPress.com stores user data in 4,096 databases. These databases can disperse large-scale data access and divert traffic and pressure.
The portability of data tables allows the code (blog) to run faster and makes the system more scalable. Relying on powerful caching strategies and flexible database utilization strategies, Matt showed people that the most popular Facebook and WordPress.com can run stably under PHP and handle an astonishing amount of traffic.
3. Never trust users – Dave Child
Dave Child is the heart of Added Bytes (previously ilovejackdaniels.com), a site famous for his excellent "cheat sheets for many programming languages". Dave works for a number of UK companies and has established himself as an authority in the programming world.
Dave provided a lot of thoughtful advice for PHP developers, and summarized it in "writing secure code in PHP": Never trust your users, they may even hurt you.
There is a basic principle of web development that I cannot repeat enough times: Never trust your users, and assume that every unit of data on your website is maliciously collected from users. code. Many times, you have to use JavaScript to verify the content submitted by the form on the client. If you are used to this, then this is a good habit. If security is important to you, this is the most important principle to learn.
Dave is currently working on organizing examples for his "Writing Secure PHP" series of books. At the end of the book, he said:
Finally, become a little paranoid. Unless you think your site will never be attacked, face the problem head on because when it does happen, you're going to be in a bad situation. You need to regard every user as a hacker who will bring about an attack and defense on the site, do everything possible to protect the security of the site, and at the same time think of solutions to the corresponding problems.
4. Use PHP caching more – Ben Balbo
Ben Balbo developed Site Point, a website that provides guidance to developers and designers. He is a member of the Melbourne PHP Development and Open Source Club, so he has a certain understanding of PHP and has certain ideas and experience in PHP caching.
If you have a site that has a lot of traffic but is not updated frequently (such as a blog, based on some kind of CMS), maybe it needs some modifications. These modifications will not take too much time, but will have a negative impact on performance. Outstanding contribution. If you want to establish a caching mechanism for a complex/fast-updating site, the process may be tortuous, but the benefits are obvious.
There are many PHP caching technologies. Ben recommended the following ones for us:
◆Cache function execution results
◆Set expiration time
◆Caching files downloaded by IE
◆Template caching technology
◆Cache_Lite
Due to the characteristics of PHP as a dynamic language, the caching mechanism is very important for sites that are not updated frequently.
5. Accelerate PHP development using IDE, Templates and Snippets – Chad Kieffer
When Chad Kieffer takes a break from UI design and database optimization, he shares a lot of technical experience on his blog 2 tablespoons. Due to Chad's comprehensive development in many aspects, he can often find problems that other programmers cannot find and form relevant experience, especially his method of developing websites. He is involved in every aspect of website development, so his advice is very useful in improving the big picture of website development.
Chad believes that using an IDE like Eclipse PDT (Eclipse’s PHP development package) and using some template technologies and open source projects can effectively increase the development speed of PHP.
Compact plans, long to do lists and deadlines make developers very frustrated. However, some features, such as Eclipse Templates, can effectively reduce coding time and the chance of errors.
Generally speaking, any project can be automated. The higher the degree of automation, the shorter the time it takes to complete the project. Taking the time to develop frameworks and templates that will be used frequently will save you even more time later. At the same time, using an IDE like Eclipse and the PDT package, you will find that your efficiency is significantly improved. The IDE can automatically close, complete semicolons and debug locally.
6. Make good use of PHP’s filter functions – Joey Sochacki
Perhaps Joey Sochacki is not as famous as Matt Mullenweg, but he is also an experienced developer and has shared a lot of technical experience through his blog Devolio
Joey found that there are many places that need to be filtered when writing PHP code, but not many coders pay attention to PHP's built-in filtering function.
Filtering data is something we often need to do, but many feature-rich PHP built-in filtering functions are unknown. Using PHP built-in functions like filter_*, we can handle almost all filtering tasks, including data type validation/URL/email and IP address validation/special character processing, etc.
Filtering is a complicated thing, but I believe joey's discovery will give you a lot of inspiration and let you realize the powerful filtering function of PHP.
7. Use PHP framework – Josh Sharp
There has been a lot of controversy over whether you should use Zend, CakePHP, Code Igniter, or other PHP frameworks, but in the minds of web developers, they have their own standards of measurement.
Josh Sharp has created a website that provides bread and butter services, so he has some experience in using PHP framework to develop websites. He believes that using a PHP framework for project development can effectively save time and reduce the chance of errors. Why? Because he thinks PHP is really easy to use.
The ease of use of PHP is sometimes flawed, because the loose syntax often leads to the creation of many erroneous codes. But if you use a PHP framework, the chance of errors will be greatly reduced.
PHP framework can make your code structure more standardized and save a lot of time.
8. Don’t use PHP framework – Rasmus Lerdorf
Contrary to Josh’s point of view, Rasmus Lerdorf, the originator of PHP, believes that it is best not to use PHP frameworks. Why? Because PHP that is not based on frameworks has better performance. In his speech at Drupalcon 2008, Rasmus used the "Hello World" example to compare the performance between some framework PHP and simple PHP. The results showed that the performance of framework PHP was far behind.
9. Using batch processing – Jack D. Herrington
Jack Herrington is no stranger to the PHP world, and has contributed more than 30 articles to the famous IBM developerWorks, and also published the book "PHP Hacks", so he is a true expert.
Herrington recommends using batch processing and Cron to replace program scripts that can run in the background. Web users are not willing to wait for your processing online, so some things are better suited to be processed in the background.
Admittedly, this is overkill in some cases, but you can clearly see that using Cron, MySQL, PHP object-oriented methods, and Pear::DB are convenient tools to create a batch processing tool and Not a complicated thing.
Jack believes that using cron, PHP and MySQL to process some tasks in the background is much more cost-effective than multi-process business logic.
I have tried both methods. I think Cron is very consistent with the "Keep It Simple, Stupid" (KISS) principle. It makes background processing simple. Compared with multi-process business logic, it has no risk of memory overflow. You can create a simple batch script and run it in cron. This script will regularly check whether there are tasks that need to be processed, and will automatically exit after processing, so you don't have to worry about whether a process is stuck or stuck in an infinite loop.
10. Enable error reporting in a timely manner – David Cummings
David Cummings has a company that specializes in providing CMS software services and has won several awards. He has very rich experience in PHP development. David once wrote "two PHP tips he wished he’d learned in the beginning", one of which is: enabling error reporting in time, which will save a lot of time.
I tell people that the most important thing is to maximize PHP’s error reporting