Original address: http://nettuts.com/tutorials/php/10-principles-of-the-php-masters/
Translation and editing: Andrew, please indicate the source if you need to reprint.
1. Use PHP when it’s right - Rasmus Lerdorf
No one understands where PHP should be used more rationally than Rasmus Lerdorf, the creator of PHP. He released the PHP language in 1995. Since then, PHP has been like a prairie fire, burning through the entire development camp. 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 for 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 every problem with PHP is unscientific and a waste of 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 on PHP. He developed the most popular blog system on the planet (supported by a strong community): WordPress. After creating WordPress, Matt and his team launched the WordPress.com platform, 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 it too expensive to scale. 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 (previouslyilovejackdaniels.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 provides a lot of thoughtful advice for PHP developers, summarized 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: never trust your users and assume that every unit of data on your website is malicious code collected from users. 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 compiling 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 develops 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 make a significant contribution to performance. . 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:
caching function running results setting expiration time caching file template caching technology downloaded by IE
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 with IDE, Templates and Snippets - Chad Kieffer
When Chad Kieffer is away from UI design and database optimization work, he will share 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 thinks using Eclipse PDT
(Eclipse's PHP development package) Such an IDE, while using some template technologies and open source projects, can effectively increase the speed of PHP development.
Tight 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, and the greater the degree of automation, the shorter the time it will take you 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.
Related posts:
WordPress was successfully upgraded to 2.3.2. Although tags are of no use to me, I still upgraded for security reasons. I really need a copy of the upgrade from 2.0.5 two years ago to the current 2.3.2. Courage and determination, fortunately there were no problems when running the upgrade locally, but the functions on the template needed some simple modifications. The online upgrade went smoothly. Many people will be wondering, didn't you just post a post asking for help with the upgrade method? Well, I have found the best tool, WordPress Automatic Upgrade plugin. This WordPress automatic upgrade plugin really makes your upgrade worry-free, because it will back up all files and data for you before upgrading. It is also "all the way to next". " type, I believe it is very suitable for bloggers who don't want to worry about upgrading. However, there is a problem. There is a problem with the export function after the upgrade. It prompts that wp-config.php cannot be found. I don't know if this problem is common or a problem with my blog. , friends who encounter the same problem please leave me a message and I will research a solution. (After research, it was found that it turned out to be a problem with the access path in the coolcode plug-in. As long as the activation of this plug-in is cancelled, the Export function can be used normally)...
Does anyone have experience upgrading from WordPress 2.0? I downloaded wordpress-2.3.2 today. I originally wanted to upgrade, but I found that the version leap is quite large and the data structure changes seem to be quite large. Upgrading is troublesome and the risk is too great, so I gave up for the time being. Who? A friend has experience in upgrading WordPress from 2.0 to 2.3. Please share it. Thank you very much. ...
Translation: "14 Great Webmaster Tools" (Part 2) Original text: http://www.conversion-rate-experts.com/articles/understanding-your - visitors/ This article is written by Andrew( http://www .achome.cn ) is independently translated. If you need to reprint, please indicate the source. Users are the best publicity and sales personnel, come and listen to how they promote it, Tell-a-Friend King—experience it now! Do you have a user recommendation system? A system that allows users to send messages to invite friends. We can see that the letters sent by these users contain the answer to the question "Why do users spend money on your website?" Many people spend a lot of time positioning themselves and developing attractive advertising words, but through user testimonials, you can find out why users prefer you. Easily collect user feedback, Kampyle—try it now! Kampyle allows users to submit user feedback on your website (through a small button at the bottom of the page). After clicking, a window will pop up for users to fill in their opinions and suggestions. Webmasters can log in to Kampyle's official website to view and manage collected user feedback. If users leave their email addresses, webmasters can easily notify users that they have received feedback and will make corresponding improvements. ...
6. Make good use of PHP's filter functions - Joey Sochacki
Maybe Joey Sochacki is not as famous as Matt Mullenweg, but he is also an experienced developer and shares a lot of technical experience through his blog Devolio.
Joey found that writing PHP code There are many places that need to be filtered in the process, 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 about 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 created his own bread-and-butter website, so he has some experience using PHP frameworks 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 feels that PHP is really easy to get started with.
PHP's ease of use sometimes has its shortcomings, because its 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.
The PHP framework can make your code structure more standardized and save a lot of time. You can read "Benefit of using a PHP framework" to get more relevant information.
8. Don’t use PHP frameworks - Rasmus Lerdorf
is exactly the opposite of Josh’s point of view. Rasmus Lerdorf, the originator of PHP, thinks it’s best not to use PHP frameworks. Why? Because PHP that is not based on a framework performs better.
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. Use 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 real 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.
Granted, this is overkill in some cases, but you can clearly see that creating a batch processing tool using Cron, MySQL, PHP object-oriented methods, and Pear::DB is not a simple task. Complicated matters.
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, and I think Cron is very consistent with the "Keep It Simple, Stupid" (KISS) principle, which 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.
The most important thing I tell people is to maximize error reporting in PHP. Why? Because PHP can hide a lot of little problems:
variables are not predefined, variables that are not available are referenced in code snippets, undefined constants are used, these factors may not seem like a big deal unless you are writing some class library using an object-oriented approach. . Often, turning off error reporting will likely cost you more to maintain your code.
Error reports can help you easily find problems with your code. If the level of the error report is high enough, subtle errors can be discovered immediately, helping you save overall debugging time.