Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mod_php vs mod_python

Why mod_python is oop but mod_php is not ?

Example :We go to www.example.com/dir1/dir2

if you use mod_python apache opens www/dir1.py and calls dir2 method but if you use php module apache opens www/dir1/dir2/index.php

like image 407
Oguz Bilgic Avatar asked Dec 10 '22 20:12

Oguz Bilgic


2 Answers

Let's talk about mod_python vs. mod_php.

Since the Python language is NOT specifically designed for serving web pages, mod_python must do some additional work.

Since the PHP language IS specifically designed to serve web pages, mod_php simply starts a named PHP module.

In the case of mod_python (different from mod_fastcgi or mod_wsgi), the designer of mod_python decided that the best way to invoke Python is to call a method of an object defined in a module. Hopefully, that method of that object will write the headers and web page content to stdout.

In the case of mod_wsgi, the designer decided that the best way to invoke Python is to call a function (or callable object) in a module. Hopefully that function will use the supplied object to create header and return a list strings with the web page content.

In the case of mod_php, they just invoke the module because PHP modules are designed to serve web pages. The program runs and the result of that run is a page of content; usually HTML.

The reason mod_php works one way, mod_python works another and mod_wsgi works a third way is because they're different. Written by different people with different definitions of the way to produce a web page.

The php page can be object-oriented. A mod_wsgi function may be a callable object or it may be a simplef unction. Those are design choices.

The mod_python requirement for a class is a design choice made by the designer of mod_python.

The reason "why" is never useful. The reason "why" is because someone decided to design it that way.

like image 162
S.Lott Avatar answered Dec 13 '22 22:12

S.Lott


Because mod_python is abstracting the URL into a "RPC-like" mechanism. You can achieve the same in PHP. I always did it by hand, but I am pretty sure there are prepackaged pear modules for this.

Note the mod_python behavior is not forcibly "the best". It all amounts to the type of design you want to give to your application, and how it behaves to the clients. As far as I see, the mod_python approach assumes that for every URL you have a function, like mapping the module structure into a URL tree. This is technically not a particularly nice approach, because there's a tight correlation between the technology you are using (mod_python) and the URL layout of your application.

On the reason why, theres' no reason. Some people like one food, and some other like another. Design is, in some cases, a matter of taste and artistic choices, not only technical restrains.

like image 40
Stefano Borini Avatar answered Dec 14 '22 00:12

Stefano Borini