Skip to main content

You Were Waiting for It. PHP Vs Python

Jose CerrejonAbout 6 minDeveloper

You Were Waiting for It: PHP Vs Python

Pythons Versus Elephants
Generated by Copilot

I hate technical interviews like everyone else. But there is SOMETHING I like about them: the questions I haven't previously asked myself. Usually, there's no time to develop an answer that one likes, you know how perfectionist I am. One of them was this week:

"What advantages do you see in Python over PHP?".

I found it interesting and decided to write an article about it from a broad and not very technical perspective.


PHP and Python. Both are high-level languages and for me, they have no rivals when it comes to creating web applications. Okay, JavaScript is also very good, but it's thanks to its frameworks (React, Angular, Vue, Express), don't deny it. 😬

I started with PHP making websites, and I have more than 15 years of experience with it. Although I still follow the scene of the latter, I have switched sides, and Python has been my favorite language for 3-4 years. I don't regret it, and it's not because of AI or Machine Learning, which also, but because of its clear and readable syntax, its versatility, and the community that supports it. But let's not get ahead of ourselves...

The Best of PHP

PHP has long been the king of web development, thanks in recent years to WordPress or frameworks like Laravel ♥️. It was designed from the beginning for creating dynamic websites as a scripting language, making it a language specifically oriented to web environments. The features that some of us, not just me, find more interesting are:

  • Specialization in Web Development: With functions and features optimized for creating dynamic content along with HTML through tags, forms, or a very simple way to manage sessions on the server.

  • Ease of Integration and Libraries: Where can't you run a PHP server today?. Any hosting is natively supported by all major hosting providers. Let's not forget that unrivaled tools like composer allow us to use libraries for any functionality we need. And the best part, almost always updated, something that can't be said for others like in the React world (Ahem!).

  • Large Community and Ecosystem Maturity: The PHP developer community is very extensive and today, experienced. A LOT. Any problem you face has already been solved in some forum, blog, or YouTube video. For me, it's an important point because when I faced Rust I felt alone in the world, especially because of its somewhat toxic community, and I'm not the only one who thinks so. I ended up abandoning it.

  • Cost-effectiveness: Well, it might be because I know a PHP framework (Laravel again! 😍) better than myself. This has allowed me to quickly launch an MVP. What would the world be without WordPress?. Although I hate it, for small or medium projects, PHP is an option I find very attractive. And it has fed many who call themselves developers, poor things.

I would comment on some technical advantages like execution speed, Namespaces, the fantastic PDO Class, or the great support for multiple architecture styles, but I don't want to extend too much and I think I'll leave it for a second more technical article.

The Best of Python

Python, created in the early 90s (December 1989 to be exact), has gained great popularity in the last decade due to its simplicity, the scientific community, Machine Learning, and okay, Artificial Intelligence, I said it.

It was created as a descendant of ABC that would attract Unix/C hackers. Its direct competitors were Perl and Ruby, but I think it has surpassed both in popularity and usage.

Its versatility and an approach that favors code readability have made it popular in the scientific community, mathematicians, and it has infected a large part of developers worldwide. This is why the world has gained a lot of popularity, and programming schools are being set up for children with Python as their language of learning. England is an example of this with the Raspberry Pi.

Unlike PHP, Python was not designed exclusively for the web, and this for me is one of its strengths, since before as developers, we had to create mostly websites (today it's a somewhat saturated market)... Bored! Not anymore.

Let's go with its strengths:

  • Clear and Readable Syntax: Which prioritizes code readability and greatly facilitates collaboration between developers and code maintainability, especially over time. One of Python's principles is: "There should be one—and preferably only one—obvious way to do it".
  • Versatility Beyond the Web: As I mentioned, Python is a multipurpose language. Besides the mentioned uses, it is useful for task automation, data analysis, GUI/TUI tools, even game development. This makes it an ideal language for developers who want to work in multiple disciplines. Versatility was one of the reasons I chose JavaScript back in the day, as it allowed me to even make mobile apps for almost a decade.

  • Powerful Frameworks for Development and Libraries: Python has powerful and modern web frameworks like Django, Flask, or the New Kid on the Block, FastAPI. They allow developing scalable, secure, and efficient applications in a short time. Python is the dominant language in the field of data analysis, thanks to the vast number of scientific libraries and tools for anything you can think of. NumPy, Pandas, Scikit-learn, Keras, OpenCV, and TensorFlow come to mind. It is currently the best option for companies that require data processing or artificial intelligence capabilities in their applications, whatever they may be.

Again, as technical features, I would comment on the simplicity of object-oriented programming, the implementation of @decorators, or the ease of integration with other languages like C or Rust.

PHP Beats Python

Despite the growing interest in Python, sorry but PHP remains a solid choice in many circumstances:

  • Performance in Web Applications: For standard web applications that require handling large volumes of HTTP requests without complex processing logic. PHP is extremely efficient and can handle multiple simultaneous requests without additional infrastructure, making it a solid choice for high-traffic applications. I affirm it, PHP is faster than Python in web applications. I'll prove it another day.

  • Affordable Hosting and Third-party Server Support: PHP is natively supported by most web servers, simplifying its configuration and deployment. Additionally, shared web hosting plans are significantly cheaper for PHP applications, reducing the total development cost, especially compared to hosting options for Python applications, which I haven't looked for much, to be honest. I've always deployed on virtual machines or dedicated servers.

  • Ease of Use with Popular CMS: As I mentioned, many popular content management systems (CMS) are based on PHP. This makes it the default choice for projects that require integration with these CMS, or for sites that rely on existing plugins and/or themes.

  • Greater Maturity in Backend Tools: PHP has a long history in backend development and has mature tools for creating RESTful APIs, authentication, and session control. These features have fed me for years, and I can't complain.

Python Beats PHP

Python has gained popularity by leaps and bounds in the last decade, and there are clear reasons why many developers and companies prefer Python over PHP:

  • Code Readability, Debugging, and Maintainability: Its clear and readable syntax makes development and debugging easier (much more at least than PHP and XDebug, what a PITA). Code maintainability is crucial, and here Python seems a bit cleaner to me. Code can quickly become chaotic in large projects if the language does not favor readability and organization. I can assure you. Yes, the architecture we use will define this, but the language also matters. Or not?.

  • Versatility and High-level Applications: Python is a complete platform for multiple purposes: Backend, Jupyter Notebook, data processing, AI. Here it wins the battle against almost all existing languages.

  • Rapid Development and Prototyping: Especially with frameworks like Django. Its "convention over configuration" approach reduces the time needed to establish a basic infrastructure. We only need to focus on business logic and functionalities.

  • Future of Artificial Intelligence and Machine Learning: I couldn't help but mention that it is the chosen language for AI and Machine Learning development. Many companies see it as the future of their businesses, thanks to its compatibility with cutting-edge tools, SDKs ready for Python by major companies offering AI, and the active community that supports these developments.

Final Words

The battle between PHP and Python has no clear winner, as it largely depends on the context and project needs.

Wait,... then I'll take a stand.

PHP remains the preferred choice for traditional web development, especially when looking for low costs and easy integration with established CMS. Python, on the other hand, is the chosen language for projects that seek a focus on modern technologies like AI and data science.

I didn't want to comment on the weaknesses of each, but I'll leave you with a couple of jokes that occurred to me while writing this article:

A PHP colleague meets another from Python: "How are you, P. GIL!. Look, go to human resources, they want to talk to you..."

A PHP lawyer in front of the judge: "...And here is where I end my line of argument, your honor. Semicolon!"

Both languages have a place in the modern development ecosystem, and each offers unique tools and resources that can be crucial for the success of a project, but I'm not going to be like others and say that both are equally good. No, they are not. PYTHON IS BETTER.

DOT (Or semicolon). 😂