#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    75
    Rep Power
    3

    How web frameworks work?


    Not really sure under which topic does this question lie. Please move it under an appropriate topic if this is not correct.

    I recently started using a web framework (web2py) to create websites and I am confused about how it works.
    Here's my current knowledge (please correct me if I'm wrong):-
    1) Web browsers can only understand HTML, CSS, Javascript and a few more languages. These only create static web pages.
    2) To create a dynamic web page you need some sort of a programming language and php is one. We have servers that convert php into html for the browser to understand.

    Using a framework it segregates my website into three parts - model, views and controller. Controller is written in python in my case. I don't understand how the client is interacting with the server.
    Servers only understand php, I suppose. But here frameworks can be in so many languages - python, C, java etc. How does the server know what to do with the python/C/java file?

    Basically how frameworks are working?
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7171
    Web browsers only understand HTML, CSS and JavaScript.

    Servers don't convert PHP into HTML; they execute PHP code, or Python code or C code or Java code or any other type of code, and the executed code generates HTML, CSS and JavaScript as output, which is then sent to the browser.

    A web framework is just a library to take a lot of the basic effort out of building a web application. Using a framework is not required.

    An MVC framework separates the application into three parts, models, views and controllers. The MVC design is just possible design for a framework, there are others.

    Frameworks are not normally implemented in more than one language as that is pretty inefficient.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    75
    Rep Power
    3
    So a server say Apache understands more than one language. How does it know whether it is python, java or c?
    Also frameworks have their own method of organizing files into folders. How does the server know where to go? Is there a default directory or something?
  6. #4
  7. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7171
    Apache itself doesn't understand any languages, however it can be configured to execute programs that do understand languages in response to a particular HTTP request. In most cases, Apache decides how to handle a particular request based on the file extension of the requested file.

    Support for particular languages is added to Apache in one of two ways: either by adding a module to Apache, or by configuring Apache to use a CGI or fast-CGI API to communicate with another program that understands how to execute the file.

    In the case of PHP, either option is possible. mod_php is an Apache modules that handles requests for PHP files by invoking the PHP interpreter on the requested file. PHP also has a CGI/fCGI program that Apache can be configured to use to execute PHP files. The CGI program also invokes the PHP interpreter to process the requested file. In both cases, the normal PHP interpreter is used to execute the PHP file, and only the input and output is passed between Apache and PHP, not the code itself.

    Similar is true of other languages.

    The web server executes the file that is requested in the HTTP request, relative to its root directory. So if the server root directory is /var/www/, and the HTTP request asks for /list.php, then Apache executes /var/www/list.php. Apache is not aware of the way in which frameworks structure files, that is handled entirely by the application code.

    The exception to this is a case where you are using a URL rewriting module like mod_rewrite. In that situation, the file that gets executed may not be the one in the HTTP request if the rewrite rules change it. The rules for rewriting URLs would be specified in a configuration file.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

IMN logo majestic logo threadwatch logo seochat tools logo