views:

708

answers:

6

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

A: 

Perhaps I misunderstand your question, but both Python and PHP support both procedural and object-oriented programming. (Though one could argue that Python's support for OO is the stronger of the two.)

Ben Blank
i compare mod_python with a apache php module
Oguz
A: 

See Class and Objects in PHP 5

Chris Bartow
+4  A: 

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.

Stefano Borini
what do you prefer for python
Oguz
I use django for web development
Stefano Borini
+2  A: 

I think you have some misconceptions about how HTTP works. Nothing in the http standard requires you to have a certain file as a resource. It is just the way how mod_php works, that for a given path, this path is translated to a php file on the disk of the server, which in turn is interpreted by the compiler.

The *mod_python* module on the other hand is much more generic, it allows you to map any resource to a call to some python object. It just happens that some configurations are available out of the box, to make it easier to start with. In most cases the dispatch of the url is managed by your framework, and how that works is up to the framework implementor.

Because of the generic nature of the *mod_python* module you are also able to access some apache features which are not available in the *mod_php* module, for instance you may write your own authentication handler, which my not only apply to your python webapp, but also to other apps in your apache as well.

Mauli
+2  A: 

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.

S.Lott
First of all thank you you your general explanation.I think the reason " why someone decided to desgin this" is very useful also this is why i asked it.
Oguz
+1  A: 

in PHP you can program your web pages the top-to-bottom scripts, procedural programming and function calls, OOP. this is the main reason why PHP was first created, and how it evolved. mod_php is just a module for web servers to utilize PHP as a preprocessor. so it just passes HTTP information and the PHP script to PHP interpreter. the PHP way of web page creation is do what you want; write a top-to-bottom script, define functions in different files and include those and call functions, or write your app in OOP, you can also use many full-featured frameworks today to make sure your application design and structure meets today best practices and design patterns.

I'm new to Python, and am not familiar with web programming with python. but as much as I know, python was not created to make web programming easier. it was intended to be a general purpose programming language, so although it might be possible to write simple top-to-bottom scripts in python and run them as web page responses (I'm not sure if such thing is possible), it is not the pythonic way, and so I think developers of the mod_python wanted web programming in python to be in a pythonic way.

farzad