views:

47

answers:

2

Hi!

I've been using for more than 12 years PHP with Apache (a.k.a mod_php) for my web development work. I've recenlty discovered python and its real power (I still don't understand why this is not always the best product that becomes the most famous). I've just discovered mod_python for Apache. I've already googled but without success things like mod_python vs mod_php. I wanted to know the differences between the two mod_php and mod_python in terms of:

  • speed
  • productivity
  • maintainance (I know `python is most productive and maintainable language in the world, but is it the same for Web programming with Apache)
  • availability of features e.g, cookies and session handling, databases, protocols, etc.
A: 

I wanted to know the differences between the two mod_php and mod_python...

PHP is more widely available on Internet hosts than Python.

I've noticed on one of my Python web sites that if I'm the first user to use Python, on that Internet host, the start up time of the Python services can be measured in minutes. Most people won't wait minutes for a web page to pop up.

Python has the same web features (cookies, session handling, database connections, protocols) as PHP.

Gilbert Le Blanc
How did you configure your python web site? Most likely, it took time to import modules. Python web app is a long run process, so it should be super fast if it's already up.
Dingle
The app is not necessarily a long running process and in worst case could be CGI which means it gets loaded on every request. For persistent process systems, lazy loading which is often the default will cause first request against application to be slow, but if it takes minutes then it is going to be more to do with the application than the hosting mechanism. Some of the hosting mechanisms allow you to preload code so this isn't an issue. In other words, just seems like bad choice of hosting mechanism and/or not configuring it the best way. Fat Python web applications also don't help one bit.
Graham Dumpleton
It is. What was taking so long was the start up of the Python services. Once they're started, Python is fairly fast. My website isn't a very popular website, so I can't say how well a busy Python website would perform, compared to a busy PHP website.
Gilbert Le Blanc
You mean something like mod_wsgi with inactivity-timeout? Then it is slow to wake up the app from the idle status. But this is a method to save RAM with many low-traffic websites on shared hosting.
Dingle
You cant generalise it though and say the reason is 'Python', it is actually the particular fat Python application and/or framework you have chosen to use. If you were to use a hello world application or light weight framework, the startup time should be insignificant and not noticeable. I have though heard of TurboGears in particular taking noticeable time to load, but that is because it imports so many Python modules in its base install even if not used. If you are executing time consuming and blocking operations on startup in your own code, that would also cause issues.
Graham Dumpleton
+1  A: 

My understanding is that PHP was designed with Internet/Web in mind, but Python is for a more general purpose.

Now most people are leaving mod_python for mod_wsgi, which is more robust and flexible.

To answer other questions:

  • speed: python is faster. (PHP is slower than both ruby and python)
  • productivity: at least the same as php with numerous libraries
  • maintenance: python is clear and neat
  • features: more than you need, I would say.

Python was not popular on web because it wasn't focused on web at all. It has too many web frameworks (more frameworks than programming languages), so the community has not been as strong as Ruby on Rails.

Dingle
Should be noted however that mod_python comes with its own mini framework where as mod_wsgi doesn't. Unfortunately, that mod_python does that makes many see it as having low barrier to getting things working (like with PHP) whereas with mod_wsgi you are going to want to install separate framework or toolkit. These days one will find these separate WSGI frameworks and toolkits are much much better than what mod_python offers and so the extra work in getting them running is well worth it.
Graham Dumpleton
I used mod_python for a short while. I remember it is very similar to how php works, just write .py files to generate html pages, but not mixed. (I may have confused it with cgi)
Dingle
The mod_python package provide differing levels of abstractions and ways of doing things. What you are talking about is like the mod_python.publisher handler. It also supported a lower level handler for arbitrary resources as well as PSP which allowed Python code in HTML like PHP.
Graham Dumpleton
It seems to me like mod_wsgi is a module that "talks" to a python framework, so this is not the same principle than mod_python, where no framework but a .py file (to the least) is required. Am I right?
Olivier Pons
I consider this answer to be a good answer, thanks for this, Regards,
Olivier Pons