Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is faster, python webpages or php webpages? [closed]

Which is faster, python webpages or php webpages?

Does anyone know how the speed of pylons(or any of the other frameworks) compares to a similar website made with php?

I know that serving a python base webpage via cgi is slower than php because of its long start up every time.

I enjoy using pylons and I would still use it if it was slower than php. But if pylons was faster than php, I could maybe, hopefully, eventually convince my employer to allow me to convert the site over to pylons.

like image 537
Echo says Reinstate Monica Avatar asked Sep 16 '08 21:09

Echo says Reinstate Monica


People also ask

Which is faster PHP or Python?

Speed is a critical factor to judge the performance of two frameworks. Each time a file is created or modified; Python converts the code into bytecode. This code compilation method makes Python quicker than PHP. PHP programmers can simply improve the speed of PHP applications by installing a variety of caching systems.

Is PHP faster than Python 7?

x. It's exceptionally faster than many programming languages, including Python. Zend Engine 3.0 was also released with PHP 7, making the programming language 2x faster than its previous version. Comparatively, Python's code compilation process is designed to be quicker, even without installing caching systems.

Are Python websites slow?

When we say Python is slow, it is slower in some regards than other languages, but the extent to which speed is required for web apps is typically low.

Why PHP is better than Python for web development?

PHP is based on object-oriented programming whereas Python is both object-oriented and procedure-oriented programming. Python is a general-purpose programming language used for backend web development. On the other hand, PHP is not designed for general-purpose programming it is only used for backend web development.


2 Answers

It sounds like you don't want to compare the two languages, but that you want to compare two web systems.

This is tricky, because there are many variables involved.

For example, Python web applications can take advantage of mod_wsgi to talk to web servers, which is faster than any of the typical ways that PHP talks to web servers (even mod_php ends up being slower if you're using Apache, because Apache can only use the Prefork MPM with mod_php rather than multi-threaded MPM like Worker).

There is also the issue of code compilation. As you know, Python is compiled just-in-time to byte code (.pyc files) when a file is run each time the file changes. Therefore, after the first run of a Python file, the compilation step is skipped and the Python interpreter simply fetches the precompiled .pyc file. Because of this, one could argue that Python has a native advantage over PHP. However, optimizers and caching systems can be installed for PHP websites (my favorite is eAccelerator) to much the same effect.

In general, enough tools exist such that one can pretty much do everything that the other can do. Of course, as others have mentioned, there's more than just speed involved in the business case to switch languages. We have an app written in oCaml at my current employer, which turned out to be a mistake because the original author left the company and nobody else wants to touch it. Similarly, the PHP-web community is much larger than the Python-web community; Website hosting services are more likely to offer PHP support than Python support; etc.

But back to speed. You must recognize that the question of speed here involves many moving parts. Fortunately, many of these parts can be independently optimized, affording you various avenues to seek performance gains.

like image 74
Ross Avatar answered Sep 19 '22 19:09

Ross


There's no point in attempting to convince your employer to port from PHP to Python, especially not for an existing system, which is what I think you implied in your question.

The reason for this is that you already have a (presumably) working system, with an existing investment of time and effort (and experience). To discard this in favour of a trivial performance gain (not that I'm claiming there would be one) would be foolish, and no manager worth his salt ought to endorse it.

It may also create a problem with maintainability, depending on who else has to work with the system, and their experience with Python.

like image 34
Rob Avatar answered Sep 19 '22 19:09

Rob