Share the top ten PHP development engineer's development principles

Source: Internet
Author: User
Keywords Network programming PHP tutorial
Tags blog business logic cache caching code course create creator

I want to dizzy, in the end I want to listen to whom? In the web development world, PHP is one of the most popular languages, and from PHP you can easily find the script you need. Unfortunately, few people use "best practices" to write a PHP program. Here, we introduce PHP 10 best practices, of course, each one is proven by masters derived.

1. Use PHP - Rasmus Lerdorf when appropriate

No one knows more than PHP, Rasmus Lerdorf, the PHP developer, who released the PHP language in 1995. Since then, PHP has been like a prairie fire burning throughout the development camp, Changed the world of the internet. However, Rasmus did not create PHP. PHP was born to address the real issues of web developers.

As with many open source projects, PHP has become popular, and popular motivation can not be explained by normal philosophies, even with some admiration. It can be a case in point, a case of a tool that solves a variety of Web problems, so when PHP was first appearing, all of this tooling was focused on PHP.

However, you can not expect PHP to solve every problem. Lerdorf was the first to acknowledge that PHP is just a tool, and PHP has a lot to do with it.

According to the different work to choose the right tool. I ran a lot of companies, in order to persuade them to deploy and use PHP, but this does not mean that PHP applies to all problems. It's just a front-end language that can solve most problems.

As a web developer, trying to solve all the problems with PHP is unscientific, but also a waste of your time. When PHP does not play, do not hesitate to try out other languages.

2. Use multi-table storage to improve scalability - Matt Mullenweg

No one wants to question Matt Mullenweg's authority over PHP, where he developed the most popular blog system on the planet, backed by a strong community force: WordPress. After WordPress was created, Matt and his team started WordPress. com platform, a free blog site based on WordPress MU. Now, Wordpress.com already has about 4 million users, who provide over 140,000 daily log entries. (To view more Wordpress.com statistics, click here.)

If anyone knows how to scale the site, that person must be Matt Mullenweg. In 2006, Matt made a forward-looking improvement to Wordpress's data structure and explained why Wordpress MU uses separate MYSQL tables for each blog, rather than stuffing all the blog data into a single huge table.

We tested this method, but found it too costly to extend its scalability. If you use a whole data structure, in the face of high traffic, you will face server hardware problems. Inside MU. Users are distributed in separate tables and can be easily organized. For example, WordPress.com stores user data scattered across 4,096 databases, which allow for decentralized mass data access for traffic and stress splitting.

The data table's migrability allows code to run faster and give the system greater scalability. Relying on its powerful caching strategy and flexible database usage strategy, Matt showed people that the most popular Facebook and Wordpress.com nowadays are stable with PHP and handle amazing traffic.

Do not believe the user - Dave Child

Dave Child is a central figure in the website Added Bytes (previously ilovejackdaniels.com), known for his excellent "cheat sheets for many programming languages". Dave serves many British companies and has established considerable authority in the programming world.

Dave gives PHP developers a lot of thought-provoking advice and sums up writing safe code in PHP: Do not trust your users, they may even hurt you.

There's a basic principle of web development that I do not think is enough for how many times to repeat it: Do not trust your users, and assume that each data unit in your site is a collection of malicious code from users. Very often, you have to use javascript to submit content on the client's test form, which is a good habit if you're used to it. If safety is important to you, this is the principle that is most important and needs learning.

Dave is currently working on tidying up examples of its "Writing Secure PHP" series of books, concluding with the book:

Finally, become paranoid. Unless you think your site will never be attacked, you'll face up to all the issues and your situation will get worse when the problem really happens. You need to think of every user as a hacker who will bring an attack and defending station, trying every means to protect the site's security, at the same time think about the solution to the problem.

4. Use PHP Cache - Ben Balbo

Ben Balbo developed Site Point, a website that provides guidance to developers and designers. He is a member of the PHP Developer and Open Source Club in Melbourne, so he has some knowledge of PHP and has some ideas and experience in PHP caching.

If you have a site that is heavily visited but less frequently updated (such as blogs, CMSs based on some sort of CMS), maybe it needs some makeovers that do not take too much time, but make a significant contribution to performance . If you want to cache mechanisms for a complex / updated site quickly, the process can be tortuous, but the benefits are obvious.

There are many PHP cache technology, Ben recommended the following for us some of the following:

◆ caching function of the results

◆ Set expiration time

Cached IE downloaded files

◆ template cache technology

◆ Cache_Lite

Due to the nature of PHP as a dynamic language, the caching mechanism is very important for sites that do not update frequently.

5. Accelerate PHP development with IDE, Templates and Snippets - Chad Kieffer

When Chad Kieffer exits UI design and database optimization, he shares a lot of technical experience with his blog, 2 tablespoons. Because of Chad's all-round development, he can often find out problems that other programmers can not find and develop related experiences, especially how he develops websites. He participated in all aspects of website development, so his advice is very useful for improving the overall landscape of website development.

Chad believes that using IDEs such as Eclipse's PDT (Eclipse's PHP development package), while using some templating and open source projects, can speed up PHP development.

The compact plan, long to do lists and deadlines make developers very depressed. However, some features, such as Eclipse Templates, can effectively reduce the coding time and error rate.

Generally speaking, any project can be automated. The higher degree of automation, the shorter time you complete the project. Spending time developing frames and templates that are frequently used will save you more time later. At the same time, using IDEs like Eclipse and the PDT package, you find that your productivity is significantly improved. Your IDE can automatically close, fill in semicolons, and debug locally.

6. Make good use of PHP's filtering function - Joey Sochacki

Perhaps Joey Sochacki is not as famous as Matt Mullenweg, but he is also a seasoned developer and shares a lot of technical experience with his blog, Devolio

Joey found that there was a lot of room for filtering in writing php code, but not too much coder focused on php's built-in filtering functions.

Filtering data is something we often need to do, but many feature-rich PHP built-in filter functions are unknown. With PHP built-in functions like filter_ *, we can handle almost any filtering task, including data type validation / URL / email and IP address validation / special character handling.

Filtering is a complex thing, but I believe the joey's findings will give you a lot of inspiration, so that you recognize PHP's powerful filtering capabilities.

7. Use PHP framework - Josh Sharp

There has been a lot of controversy over whether Zend, CakePHP, Code Igniter, or other PHP frameworks should be used, but they have their own measure of standards among web developers.

Josh Sharp founded his own website serving bread and butter, so he has some experience with using PHP frameworks to develop websites. He thinks using a PHP framework for project development can save time effectively and reduce the chances of mistakes. Why? Because he thinks PHP is very good to get started.

PHP's ease-of-use is sometimes flawed, because not-so-strict syntax often leads to the birth of many error codes. However, if you use a PHP framework, the chances of error will be greatly reduced.

The PHP framework can make your code structure more standardized, and save a lot of time.

8. Do not use the PHP framework - Rasmus Lerdorf

In contrast to Josh's point of view, Rasmus Lerdorf, the PHP originator, thinks it's best not to use the PHP framework, and why? Because PHP does not work better with frameworks. In a presentation at Drupalcon 2008, Rasmus compared the performance of some framework PHP to that of simple PHP using the example of "Hello World," which showed that framework PHP lagged far behind.

9. Use Batch - Jack D. Herrington

Jack Herrington is no stranger to the PHP world and has contributed over 30 articles to the prestigious IBM developerWorks, and has published "PHP Hacks," so he is a real expert.

Herrington recommends using batch and Cron instead of those running in the background, Web users are not willing to wait for your process online, so there's something more suited to being put in the background.

Admittedly, this is a bit overkill in some cases, but you can clearly see that it is not the case that using the Cron, MySQL, PHP object-oriented methods, and the convenient Pear :: DB tools to create a batch tool Complex things.

Jack believes that using cron, PHP, and MySQL to handle some tasks in the background is far more cost-effective than multi-process business logic.

I've tried both approaches, and I think Cron is very much in line with the principle of Keep It Simple, Stupid (KISS), which makes background processing easy. It has no risk of memory overflow compared to multi-process business logic. You can create a simple batch script and run it in cron. The script periodically checks for tasks that need to be processed and automatically exits after processing, so you do not have to worry about whether there is a process stuck or getting stuck in an endless loop.

10. Enable error reporting promptly - David Cummings

David Cummings has a dedicated CMS software services company, and received several awards, he has a very rich PHP development experience. David once wrote "two PHP tips he wished he'd learned in the beginning," one of which is: Timely enable error reporting, which will save a lot of time.

I tell people, the most important thing is to maximize PHP error reporting, and why? Because PHP may hide many small problems:

◆ Variables are not predefined

In the code snippets referenced variables are not available

◆ Uses undefined constants These factors do not seem to matter, unless you're writing some class libraries using object-oriented methods. Often, turning off error reporting will probably make you pay more for your code.

Bug reporting can help you easily find the problem with the code, if the level of error reporting is high enough, subtle mistakes can be immediately found to help you save the overall debug time.

Related Article

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.