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.


Asked by: Lucas522 | Posted: 01-10-2021






Answer 1

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.

Answered by: Lana902 | Posted: 02-11-2021



Answer 2

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.

Answered by: Max963 | Posted: 02-11-2021



Answer 3

I would assume that PHP (>5.5) is faster and more reliable for complex web applications because it is optimized for website scripting.

Many of the benchmarks you will find at the net are only made to prove that the favoured language is better. But you can not compare 2 languages with a mathematical task running X-times. For a real benchmark you need two comparable frameworks with hundreds of classes/files an a web application running 100 clients at once.

Answered by: Vanessa582 | Posted: 02-11-2021



Answer 4

PHP and Python are similiar enough to not warrent any kind of switching.

Any performance improvement you might get from switching from one language to another would be vastly outgunned by simply not spending the money on converting the code (you don't code for free right?) and just buy more hardware.

Answered by: John852 | Posted: 02-11-2021



Answer 5

It's about the same. The difference shouldn't be large enough to be the reason to pick one or the other. Don't try to compare them by writing your own tiny benchmarks ("hello world") because you will probably not have results that are representative of a real web site generating a more complex page.

Answered by: Briony401 | Posted: 02-11-2021



Answer 6

If it ain't broke don't fix it.

Just write a quick test, but bear in mind that each language will be faster with certain functions then the other.

Answered by: Aldus357 | Posted: 02-11-2021



Answer 7

You need to be able to make a business case for switching, not just that "it's faster". If a site built on technology B costs 20% more in developer time for maintenance over a set period (say, 3 years), it would likely be cheaper to add another webserver to the system running technology A to bridge the performance gap.

Just saying "we should switch to technology B because technology B is faster!" doesn't really work.

Since Python is far less ubiquitous than PHP, I wouldn't be surprised if hosting, developer, and other maintenance costs for it (long term) would have it fit this scenario.

Answered by: Emma344 | Posted: 02-11-2021



Answer 8

an IS organization would not ponder this unless availability was becoming an issue.

if so the case, look into replication, load balancing and lots of ram.

Answered by: Brad192 | Posted: 02-11-2021



Answer 9

The only right answer is "It depends". There's a lot of variables that can affect the performance, and you can optimize many things in either situation.

Answered by: Daniel173 | Posted: 02-11-2021



Answer 10

I had to come back to web development at my new job, and, if not Pylons/Python, maybe I would have chosen to live in jungle instead :) In my subjective opinion, PHP is for kindergarten, I did it in my 3rd year of uni and, I believe, many self-respecting (or over-estimating) software engineers will not want to be bothered with PHP code.

Why my employers agreed? We (the team) just switched to Python, and they did not have much to say. The website still is and will be PHP, but we are developing other applications, including web, in Python. Advantages of Pylons? You can integrate your python libraries into the web app, and that is, imho, a huge advantage.

As for performance, we are still having troubles.

Answered by: Maria749 | Posted: 02-11-2021



Similar questions

php - Two ways to make python based webpages?

I wanted to try out python to create webpages instead of using php. However I came across that you need either mod_python or mod_wsgi installed to apache to make it play with python. If you now use pure, i'm not sure if it should be said pure, python code, not using any web frameworks like django. I found out that making a simple page looks differently in mod_python and in mod_wsgi. How come?, the more I looked int...


python - Extract texts from webpages

I am trying to parse text from webpages, starting at this page. This page has links to the final page (this can be moved in to text file manually also; in order to avoid extra effort on coding). On the final page on the left hand side there is a page index. And each page also has a page index. Th...


python - Take a Json object from three webpages and write that in a file?

I am trying to write a python script that will take a json object from a web page and write it to a flat file. There are ten lines in the flat file and three web pages. I have come to this code with the help of various online resources: #!/usr/bin/python import requests import simplejson r = requests.get('https://github.com/timeline.json') c = r.content j = simplejson.loads(c) for item in j: print it...


python - Display links to new webpages created

I'm building a website with Python (using heroku) and I would like to create a "newest submissions" section. That is, when I create a new @app.route(blah) in my Python app, I want a link to the new page to show up under the "newest submissions" section on my homepage. Is this possible? EDIT: here's my code import os import json from flask import Flask, render_template, url_for ...


Using Python 3.3 to access blocked webpages

I'm trying to download webpages off the internet. I'm able to steal the HTML (with URLlib), but I can't download images correctly. There's already a question for that though. My question is, is there any way I can use python to bypass a firewall to access 'blocked' webpages? Ideally it would be using some obscure code or module, but if it's impossible, could someone tell me a good workaround using a differen...


How do I view webpages using python

I have a project, and needed some help. I need to view the search results from Google for a user input WITHIN python (basically print whatever Google says). So, if the user inputs 'Python', I have to give the results for that from google. I could do this this till now. import webbrowser as wb usrinput = input("Enter search query: ") wb.open('https://www.google.co.in/?#q=' + usrinput) ...


python - Using lxml or ??? to extract information from webpages

currently I have the following code: # Import der Pythonmodule import urllib import lxml import mechanize import sys # Verbindung zum URL aufbauen try: URL = urllib.urlopen("http://...") except: print "Verbindung zum URL fehlgeschlagen" sys.exit(0) # Quellcode des URL lesen URL_quellcode = URL.readlines() # Verbindung zum URL beenden URL.close() So far so good, I can open ...


python - Trying to save information on different webpages

I have a website where there is information about topic (explaining what it is). Each topic has its own webpage. Each webpage is set up the same, and I want to retrieve this information all automatically. I was thinking on using something like wget to grab the info automatically, but Im new with wget so I dont know if it will work nor do I know how I would run it to go to each page and get the information I want. I...


python - Crawl Spider for nested webpages doesn't work

Below spider doesn't crawl web site, I would like to know if I used wrong code to crawl multiple pages within same web site. Here is the code TestScrpy.py : from scrapy.spider import BaseSpider from scrapy.selector import HtmlXPathSelector from scrapy.contrib.spiders import CrawlSpider, Rule from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor import scrapy from scrapy.contrib.l...


python - How to crawl all webpages on website up to certain depth?

I have a website and I would like to find a webpage with information about job vacancies. There is only one page usually with such information. So I start crawling with website and I manage to get all webpages up to certain depth. It works. But they are many times duplicated. Instead of lets say 45 pages I get 1000 pages. I know the reason why. The reason is that every time I call my "parse" function, it parses all the web...






Still can't find your answer? Check out these communities...



PySlackers | Full Stack Python | NHS Python | Pythonist Cafe | Hacker Earth | Discord Python



top