10 rules of PHP-masters
1. Use PHP only when it is necessary – Rasmus Lerdorf
There is no better source than the creator of PHP, to learn what he can do. Rasmus Lerdorf created PHP in 1995. Since then, the language has spread like a wildfire rate in the developer community, incidentally changing the face of the Internet. However, Rasmus did not create PHP with these intentions. PHP was created for the needs of web development.
As is the case with many other projects with open source, have become popular, philosophy or even narcissism has never been the driving force. It was a pure case needs a tool for solving global problems related to the Net. In 1994. When it comes to web development tools, the choice was very limited.
And yet you can not use PHP for everything. Lerdorf first noted that PHP is really just another tool in the arsenal of the developer, and even PHP has limitations.
For work, use the right tool. I have seen companies that relied entirely on PHP, to use his absolutely everywhere, even though it was never intended to be a general-purpose language, suitable for any problem. It is most acceptable as an external scripting language for the Web.
Trying to use PHP for anything counterproductive, and certainly is not the best way to use your time as a web developer. Do not be afraid to use other languages if PHP for your project does not fit.
2. Use multiple tables in PHP and my-SQL for Scalability – Matt Mullenweg
There is no need to doubt the competence of Matt Mullenweg in PHP. He (along with the user community) has developed the most popular blogging system in the world: Wordpress. After creating a Wordpress Matt and company have launched star Wordpress.com, a free blogging site based on platform Wordpress MU for multiple blogs. Wordpress.com currently supports more than 4 million blogs, and their users now have written over 140,000 posts.
If anyone knows how to scale web sites, this is Matt Mullenweg. In 2006. Matt provided an opportunity for some to consider the internal structure of databases, Wordpress, and explained why, in Wordpress MU for each blog uses a separate table for my SQL, instead of one giant table common to all blogs.
We tested this approach for MU, and found that the scale becomes too expensive, starting at some point. With monolithic structures you run into a wall constructed of hardware features. In MU users are separated and can be easily separated, for example, Wordpress.com users distributed over 4,096 databases, which makes it very easy and rational scale of hundreds of thousands and even millions of users, providing an extremely high level of traffic.
Possible migration of tables allows the code and, eventually, blogs are much faster to run and easier to scale. Combining extensive caching and elegant use of databases, Matt has shown that extremely popular sites like Facebook and Wordpress.com can only work on PHP and process an incredible amount of traffic.
3. Never, ever trust your users – Dave Child
Dave Child – Fibber (hi-hi!) behind the recently renamed Added Bytes (formerly ilovejackdaniels.com), a website which contained a magnificent crib Dave for many programming languages. Dave worked for many software companies in the UK and has strengthened his position of authority in the programming world.
Dave offers wise advice about writing secure code in PHP: Do not trust your users. They may disappoint you.
Dave continues to provide special examples of safety practices in parts one, two and three of its series of publications ‘Writing secure PHP’. And his final verdict is:
In the end, be entirely paranoid.
If you suspect that your site will never be subjected to attack or not collide with any other problem, when something suddenly goes wrong, you have profound difficulties. If, on the other hand, you believe that every visitor is going to get you, and you are constantly in a state of war, it will help keep the site safe and be fully prepared in case things go wrong.
4. Pay attention to PHP-caching – Ben Bolbo
Ben Bolbo writing for Site Point, a very reputable site, a textbook for our brother – the developer and designer. He is a member of the commission as the Melbourne User Group PHP, and Club project developers with open source, so that he knows something about the language. Not surprisingly, based on his past as a PHP developer and instructor, he recommends that a little more attention and training PHP-caching.
If you have a busy and predominantly static web site – such as a blog – which manages the content management system, caching, may require minor alterations, but will provide a significant improvement in performance with little cost of your time. Organization of caching for a more complex site that generates content for each user, such as a portal or an e-shop will be a bit more complicated and will take time, but the benefit of it is obvious.
In PHP, there are many techniques of caching and Ben touches in the article a few very large, such as:
Caching function calls
Installing headers expiry
Caching file downloads in IE (Internet Explorer)
and much more. Due to the dynamic nature of languages such as PHP Caching is a crucial factor productivity by providing storage of the parts of pages that are being continued access and who often do not change.
5. Accelerate development using PHP IDE, templates and snippets – Chad Kieffer
When Chad Kieffer is not busy improving user interfaces and database management, it provides expert advice on his blog two tablespoons. Because of its broad capabilities and professional experience, Chad can often see the big picture that other programmers cannot see, especially when it comes to a holistic approach, which is used by Chad in the development of websites. He is an expert in all aspects of the development process, so that any ability to penetrate to the heart, which he shares, can be useful in the process of building the project into one.
Chad believes that the use IDE like Eclipse PDT (package for PHP development in Eclipse) with a mixture of templates and fragments can really accelerate the development cycle of the project.
Overcrowded schedules, long lists of required status and deadlines make it difficult for developers to get acquainted with some advanced features, which have their instruments. Assume you will be ashamed of it, because some features such as templates, Eclipse, can really reduce coding time and reduce errors.
Common sense says that every time when you can automate the task possibly see the project finished quickly. The same is true with respect to the theory of Deng. By taking the time to create templates that can be used again and again, you will save a lot of time by automating the repetitive parts of the code.
Using the IDE like Eclipse and package PDT, you’ll find that development time is definitely faster. The IDE will automatically close brackets, add missing semicolons, and even allow you to fix problems in a text editor, without having to re-upload to the server.
6. Better filtering capability PHP – Socheki Joey
Joey has found that, although when writing PHP code should be a lot of filtering, few programmers use functions of filtering PHP.
Filtering data. We all have to do it. Most if not all of us, treated him with contempt. However, most remain unknown filtering PHP, which allow all sorts of filtering and validation (validation). Using the functions of PHP filter_ *, you can verify the correctness and “sterilize” data, URLs, addresses, e-mail, IP-addresses, cut off the bad characters and much more, relatively easily.
7. Use frameworks PHP – Josh Sharp
Over whether to use a PHP framework such as Zend, CakePHP, Code Igniter, or any other, always arguing. Its use has its positive and negative aspects, and many developers have their own opinion, follow this path or not.
Josh Sharp – a web developer, who earns his bread and butter creating websites for clients. That’s why you should believe him when he says that the use of framework PHP – a great way to save time and eliminate errors during programming. Why? Josh said, because PHP is very easy to learn.
But ease of use of PHP also lead to collapse. Because of fewer constraints in the structure of the code is much easier to write bad code. But for this problem has a solution: use a framework.
8. Do not use frameworks PHP – Rasmus Lerdorf
Contrary to the opinion of Josh that you want to use framework, PHP, Rasmus Lerdorf, the Godfather himself PHP, believes that frameworks are not so good. Why? Because they perform the operation is much slower than plain PHP.
During his presentation at Drupalcon 2008 Rasmus compared the response time for PHP-page using a simple example “Hello World”, with multiple frameworks PHP (slides 24-32) and showed that PHP frameworks are much slower than straight PHP.
9. Use batch processing – Jack D. Herrington
Jack Herrington is familiar with PHP and the sphere of development. Following the writing of more than 30 articles for the prestigious IBM developer Works, Jack has also published a book on programming, such as «PHP Hacks». Jack – a true connoisseur.
Herrington recommends using batch processing for complex tasks that can be processed in the background. The work, which takes a long time, is better suited to run in the background.
Naturally, in some cases a little easier to run a helper thread to handle small tasks. But it is easy to see that when using the traditional tools – cron, My SQL, a standard object-oriented PHP and Pear:: DB – batch jobs in PHP applications to easily create, easy to deploy and easy to maintain.
10. Immediately turn on error reporting – David Cummings
David Cummings manages his own software company that specializes in content management systems and has won several awards.
David wrote an article on Site Point about two tricks PHP, which he would like to know from the outset. One of them: Immediately turn the error reporting. This will save considerable time over a long period.
The single most important thing I’m talking about people using PHP, is to turn error reporting to maximum. Why would I want to do this? Typically, error notification is set to a level that hides a lot of little things, such as:
Premature declaration of the variable.
Access to a variable that is not available in this segment of code, or
Using a definition that has not been established
These factors might not seem quite so important – as long as you develop structured or object-oriented programs with functions and classes. Too often, writing code without error reporting, included in the maximum level will cost you hours of debugging long functions that do not work because the variable is written with misspelled or unavailable.
Since error reporting is much easier to find the cause. A tiny defect in the code, you can quickly identify if the error reporting PHP includes to the maximum. Thus saving yourself time and hassle by allowing PHP for you to find defects.