Thoughts on three mainstream web Architectures

Source: Internet
Author: User
Tags api manual zend framework

The following is an example of PHP implementation, But I think Java,. net, and Ruby developers should be easy to understand. The last is my evaluation of Delphi fo PHP, which has attracted the attention of countless people since its launch.

WebProgramThe architecture can be basically divided into the following three types:

(1) based on "Web Pages/Files", such as CGI and PHP/ASP programs. Program files are stored in different directories, which correspond to URLs. When an HTTP request is submitted to the server, the URL directly points to a file, which then processes the request and returns the response.

Like http://www.website.conm/news/readnews.php? Id = 1234

As you can imagine, we put a readnews. php file under the news directory in the root directory of the site.

This development method is the most natural, easy to understand, and the most commonly used PHP method. Note that the generated URL is unfriendly to the search engine. However, you can use the URL rewriting solution provided by the server, such as Apache mod_rewrite.

(2) Based on "action ). This is the most common way for MVC-based web programs. Currently, mainstream web frameworks such as struts, webwork (Java), Ruby on Rails (Ruby), and Zend framework (PHP) all adopt this design. The URL is mapped to the action in the controller and the action in the controller. The action is used to process the request and output the response result. This design is the same as the file-based method above. It is a request/response-driven solution and cannot be left without HTTP.

Like http://www.website.com/news/read/id/1234

As you can imagineCode. Different frameworks may be implemented in a slightly different way by default. Some are a controller file with multiple actions and some are a file with each action. Of course, you can control these items by yourself.

URLs in this way are usually very beautiful and friendly to search engines, because many frameworks have their own URL rewriting functions. You can specify the location of the controller, action, and parameter in the URL.

In addition, there is a more direct URL-based design scheme, namely rest. By manually specifying the URL structure (for example, there are only a few types of actions) to promote mutual access between websites, reduce development complexity, and improve system scalability. Rest is an innovation for Web Services.

Although this article discusses the architecture used by a single project, and rest is to solve the communication problem between websites, but the emergence of rest, it will affect the architecture of a single project (it is clear that you need to construct a standard URL during development ). Mixing rest and MVC in the future is also a trend. Ror provides good rest support. Zend framework also provides zend_rest to support rest, including server and client.

(3) The most common architecture is Microsoft's. net. The basic idea is to divide the program into many components. Each component can trigger an event and call a specific event processor for processing (for example, setting an onclick event to a PHP function on an HTML button ). This design is far away from HTTP. HTTP requests are completely abstracted and mapped to an event.

In fact, this design is most often used in the development of traditional desktop GUI programs, such as Delphi and Java swing. All presentation layer components, such as Windows and HTML forms, can be provided by IDE. You only need to click or drag the mouse in IDE to automatically add a component, add an event processor.

This development method has the following advantages:

Reusability-code is highly reusable.

Easy to use-generally, you only need to configure the properties of the control and write related event processing functions.

I personally like this method. Pear provides a very powerful html_quickform, which is used to add form elements and event processing functions on the page. It can also be combined with template engines such as smarty. This is a complementary feature for project development. Using quickform in some parts of the project can greatly accelerate development.

The component-based and event-driven development framework is not new to PhP, and Prado is such a framework. It once won the first prize in the Zend Programming Competition. However, it is clear that this development method promoted by Prado is still not accepted by most PHP programmers. Why?

I think there are two main problems:

(1) efficiency issues

This does not mean development efficiency, but code execution efficiency. As we all know, PHP Execution is quite efficient under normal circumstances. However, the efficiency of the control-based framework is currently a problem. Prado itself provides a caching mechanism to alleviate this problem. If caching is not used, it can be said that many sites cannot use frameworks such as Prado, such as portal websites and large forums.

However, Asp. net is not the same, because it is a compilation framework, and the final generated code is compiled and generated, so there is no need to re-process the intermediate process, so after the first execution, the speed will be very fast, the execution efficiency is still very high. This is a language-level function, and Prado cannot completely make up for it through code-level efforts.

(2) No powerful ide support

Setting the properties of a control and adding its corresponding event processor seem simple, but it is also a heavy task to add more controls .. Net is powerful because it frees programmers from repetitive work, setting attributes is very convenient, and the event processor will be automatically added. Prado does not currently support this IDE.

In short, this control-based framework is more suitable for applications with a large amount of user interaction. You need to set different processing operations for many components on the page, but for applications with low performance requirements. In addition, frameworks with component support generally have better support for Ajax, such as. NET and Ruby on Rails.

In summary, the three architectures can basically represent all mainstream web development methods, including PHP, javaee,. net, Ruby/ror.

Current PHP Development Status and Future Trends:

I usually do a lot of PHP work. I would like to summarize the development trend of PHP. Currently, in PHP development, we usually use a "file"-based architecture, which is actually a "process-oriented" development method. Generally, the purpose of writing a PHP program is to "get online quickly and run the program ". Most PHP programmers have to fight closely with HTML and CSS, so it is difficult to adjust the visual effect if the program is too abstract. This is the best choice for small projects.

But more and more people are realizing that object-oriented and MVC frameworks can facilitate code reuse and sharing, and programs are easy to expand. As the complexity of programs increases, this trend is becoming more and more obvious. So the OO framework is emerging. Currently, the most promising PHP frameworks are CakePHP, symphony, and Zend frameworks.CommunityAnd a large user base are growing rapidly. PHP frameworks are designed for rapid development and actively imitate and absorb the new features of the excellent frameworks such as ror. With the popularity of PhP5 and the maturity of these frameworks, coupled with the huge number of people in the original php development community, some industry standards may emerge in the future.

This option is suitable for medium and large projects, especially for large teams and long-term maintenance and secondary development. I personally think This is the trend of php development in the future.

Most PHP programmers are not interested in component-and event-driven development. However, many people are doing this. For example, codegear's Delphi for PHP attracts the attention of many people. If you have strong business support, you may have a place in the development market in the future.

In the next articleArticleIntroduces New Features of d4p and evaluates them.

Future prospects for web development:

With the popularity of HTTP rest, I think the methods of abstract components like. NET and Java will be affected. Because these components are not as convenient as they promise. In the future, the MVC + rest + Ria model will become more popular.

Ajax is a double-edged sword, although the event-driven architecture seems very suitable for processing asynchronous requests (it can be imagined that there are several components in the page, each component can trigger asynchronous requests, corresponding to an event processor on the server, it looks like an ideal processing method), but it is not easy to automatically generate good JavaScript code for the client, to meet the compatibility requirements of various browsers, you must be able to expand on your own to meet the strange demands of the project. In many cases, I prefer to use some JS frameworks such as prototype to develop various effects on my own, rather than generating them on the server. Two JS results are generated on the server side. One is not trusting the generated code, and the other is being silly because you don't know what actually happened.

(A bit of complaints are also posted)

Personal questions about web development:

L in order to make development easier, we have to learn to use complex development tools and frameworks. Is this an improvement or a degradation?

L does ide make programmers smarter or stupid? We can design the client interface in the server code. Is this progress or degradation?

For example, Microsoft's ASP. NET Ajax allows us to design various asynchronous controls on the server side. So programmers can even design various client effects without JavaScript and without understanding Ajax. What should you do if a project needs to be designed with a slightly complex effect and cannot be completed automatically by the IDE and framework? It may be too late to learn JS again at this time. What's even more terrible is that the technology is being updated and eliminated. Ten years later, you may find that you are very familiar with few technologies except for various ides, if you leave the IDE, you need to check the API manual for a long time to write a small program, because you usually rely on "auto-completion" to write code! I think no one is willing to do this.

it may be an improvement for short-term development projects, but it is not a good thing for individual programmers to grow. Our dependence on tools has led to our lack of in-depth understanding of the underlying and core technologies, limiting personal growth.

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.