1 / 19

Server- side Scripting

Server- side Scripting. Martin Kruli š. Web Server (Revision). Serving Static Pages. Apache configuration. HTTP Request GET / myweb /index.html. / var /www/ myweb /. `. Internet. Client. Web Server. HTTP Response HTTP/1.1 200 OK Content-Length : 1019 Content-Type: text/html ; ...

salcedo
Download Presentation

Server- side Scripting

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Server-sideScripting Martin Kruliš by Martin Kruliš (v1.0)

  2. Web Server (Revision) • Serving Static Pages Apache configuration HTTP Request GET /myweb/index.html ... /var/www/myweb/ ` Internet Client Web Server HTTP Response HTTP/1.1 200 OK Content-Length: 1019 Content-Type: text/html; ... <contents of index.html> index.html by Martin Kruliš (v1.0)

  3. Web Server (Revision) • Serving Dynamic Content HTTP Request GET /myweb/app.cgi ... /var/www/myweb/ ` Internet stdin app.cgi stdout Client Web Server HTTP Response HTTP/1.1 200 OK Content-Length: 2049 Content-Type: text/html; ... <contents generated by cgi> by Martin Kruliš (v1.0)

  4. CGI • Common Gateway Interface • One of the first standards for generating dynamic web content • NSCA specification from 1993 how to invoke command line applications • Current version CGI 1.1 (RFC 3875) from 2004 • Specifies only the interface • Application may be written in any language • Important information and headers are set as environ-ment variables, POST body is directed to std. input • Response is taken from the std. output Example 1 by Martin Kruliš (v1.0)

  5. FastCGI • CGI Issues • Starting a process takes some system time • Each process handles exactly one request • Unable to keep session/shared data in memory • Fast CGI Improvement • Fast CGI server runs independently on web server • Keeps the process pool, resources, … • Communicates with web server via socket/TCP • Multi-request processing may be achieved by multiplexing, or multiple connections (or both) by Martin Kruliš (v1.0)

  6. Web Server (Revision) • Integrating Scripting Modules HTTP Request GET /myweb/index.php ... /var/www/myweb/ ` mod_php Internet index.php Client Web Server HTTP Response HTTP/1.1 200 OK Content-Length: 1984 Content-Type: text/html; ... <contents generated by php> by Martin Kruliš (v1.0)

  7. PHP • PHP: Hypertext Preprocessor • Popular language originally designed for the web • The language has integrate API for handling requests • PHP script code can be directly interleaved with • Things like URL parameters, POSTed data, headers,or server settings are presented in global variables • HTML (or other type of generated content) • The script is embedded between <?php, ?> marks • The PHP interpret process the script and replace its body with its output in the document Example 2 by Martin Kruliš (v1.0)

  8. WSGI • Web Server Gateway Interface • Universal interface between web servers and web applications designed for the Python language • Interface is called WSGI middleware and it is implemented by both sides (server and application) • Specific new features • Routing requests to application objects (by URL) • Multiple applications may run in one process • Content post-processing (e.g., by XSLT) • Load balancing (remote processing, forwarding, …) • Similar APIs • Rack (Ruby), PSGI (Perl), JSGI (JavaScript) Example 3 by Martin Kruliš (v1.0)

  9. Server-side Scripting • Client-server Architectures • Strict separation of two application parts • Client - data presentation, user interface • Server – business logic, data storage • Both sides are connected via specific API (HTTP) • The communication latency and overhead influence the application design • Three-tier architecture • Server part is overloaded, so we separate the data storage and management into separate tier • Thick client • Functionality is slowly shifting to the client-side by Martin Kruliš (v1.0)

  10. Server-side Scripting • Specific Issues • Traditional web applications • Work in batches – client wants to perform a large task with each HTTP request • Download a page full of formatted data • Submit a form and generate a response • Difficult state management (HTTP is stateless) • Code replication and dependency injections • Modern web applications • Just a remote API for AJAX calls • Difficult to integrate AJAX API into existing applications, or create applications that work both ways by Martin Kruliš (v1.0)

  11. Web Design Patterns Application logic, processing requests, orchestrating other components, … • Model-View-Controller Controller Presenting data, rendering web pages, … Providing interface with the data storage, … View Model Invoking actions Dataflow Database by Martin Kruliš (v1.0)

  12. ASP.NET • ASP.NET • Microsoft solution built on .NET platform • Supports all .NET languages (C#, VB, …) • Successor to Microsoft’s Active Server Pages • Requires Microsoft IIS web server • Mono version (mod_mono and FastCGI) exists • WebForms • Basic building blocks for ASP.NET web pages • Similar HTML interleaving syntax as PHP • The idea is to design web pages in the same manner as desktop applications by Martin Kruliš (v1.0)

  13. ASP.NET Example 4 • ASP.NET • WebForms • Event-based model, events may be processed at server • The forms automatically serializes the whole state • Razor syntax • Block starts with @ and doesnot require explicit closing • MVC • Alternative type of ASP.NET applications • Default view engine is either Razor (.cshtml, .vbhtml), or Web Forms (.aspx) • Controllers are .NET classes, methods are actions • Routers select controller class and invoke an action by Martin Kruliš (v1.0)

  14. JSP • Java Server Pages • Java-based solution for dynamic web pages • Requires web server with servlet container • Apache Tomcat, Jetty, … • Supports both “simple” PHP-like approach and MVC • Uses <%, %> marks for scriptlet-HTML interleaving • MVC usually uses JavaBeans as the model and Java servlets as the controller • Java compilation • Compiler is integrated in the web server and compiles the page when first needed (or when changed) by Martin Kruliš (v1.0)

  15. Ruby on Rails • Ruby on Rails • Ruby scripting language + Rails web framework • Basic philosophy • DRY (Don’t Repeat Yourself) – avoid code duplication • Convention Over Configuration – our way is the “best” • Very strict style of application development • Improves efficiency, but ties your hands • Specific structure of the application • Reflects the MVC pattern • $> rails new myapp • Generates new application structure in ./myapp Example 5 by Martin Kruliš (v1.0)

  16. Ruby on Rails • Representational State Transfer (REST) • Architectural abstraction for distributed systems • The application is formed by resources • Resources are identified by URL http://myapp.com/galery/2013 http://myapp.com/galery/2013/photo/42 • Components of the application communicate over the network and exchange resource representations • Representation is typically HTML, XML, or JSON • The API is built over HTTP and hypertext driven • GET http://myapp.com/galery/2013 • DELETE http://myapp.com/galery/2013/photo/42 by Martin Kruliš (v1.0)

  17. Node.js • JavaScript Server-side Platform • Basically a Google V8 JavaScript engine compiled as CLI script interpreter • V8 is used in Chrome and it is the fastest JS interpreter • Contains many pre-built packages for server-side application development (sockets, HTTP, …) • HTTP server is embedded in the application, so the programmer may tune it for specific needs • Aims for fast developed single-language solutions • Using JS on client and server allows some code sharing Example 6 by Martin Kruliš (v1.0)

  18. Statistics by Martin Kruliš (v1.0)

  19. Discussion by Martin Kruliš (v1.0)

More Related