Python vs. PHP in 2018

Python vs PHP

Hackr.io.

Backend development is one of the most sought-after skill today. Almost any new business/startup needs a website and a mobile app – both of which connect to a server in the backend. Therefore, backend developers are high in demand in the market and companies are willing to throw large sums of money to developers who can manage the backend well.

Many programming languages that are being used for backend development are emerging in the market:

  • Python: Python is one of the most popular choices of backend programming. It is relatively new and has enormous library support.
  • PHP: PHP has been in the market for a long time and it is widely used even today. Facebook, for instance, has its substantial backend developed in PHP in initial days.
  • JavaScript: With powerful web frameworks like NodeJS, JavaScript has captured a huge chunk of the market and emerged as one of the most popular backend programming languages.
  • Ruby: Ruby on Rails is one of the most popular web development frameworks and currently tons of startups use it.
  • Dot NET: Though it is quite old, many legacy applications still use it as the backend.

For new developers, it is always a matter of confusion – which backend framework to learn? With so many new programming languages which offer so many features, libraries, and frameworks, how does one actually decide on which web framework to learn? In this blog post, we will try to compare 2 of the most popular backend programming languages – Python and PHP. We will try to cover various aspects and see which one of them wins.

Before we do the comparison, let us first list the points of comparison which significantly will affect our choice of web framework:

  • Ease of learning: this is arguably one of the most important parameters to decide which web framework is to be used. If the programming language is difficult to learn, there is no point spending time on it. Today, developer time is more important than execution time for all practical purposes.
  • Community support: let us face it – we all struggle with bugs, we all face issues while writing programs and we all look for support online at StackOverflow and other forums. If a particular programming language isn’t well known and there is little community support available, it is better to stay away from it.
  • Documentation: just like community support, it is essential that the programming language/framework has sufficient documentation available for the developers to learn and understand the nuances.
  • Pricing: some tools/frameworks aren’t free. It might significantly affect the choice of an organization that is low on budget. Generally speaking, a large number of tech companies prefer to use open-source tools and frameworks rather than using paid systems. However, enterprises like banks, insurance companies, etc. prefer to use paid systems.
  • Library support: if the programming language is widely used, there will be more developers who will be developing libraries for the particular language. As a result, development becomes even easier.
  • Speed: server-side applications may require high tolerance capacity as well as low latency. Therefore it is important to see which language is faster in terms of execution time.
  • Choice of web frameworks: it is important that the programming language provides well-designed web development frameworks that are easy-to-use and develop powerful applications.
  • Debugging: the choice of programming language should also depend on the available debugging tools available for the language. Lack of good debugging tools means that the developers are going to spend more time in debugging which essentially isn’t the most productive use of time.

PHP vs Python Performance Comparison

Now let us get to each of the above factors and see how Python and PHP compare with each other.

Ease of Learning

Without any doubt, Python is much easier to learn. Python is a general-purpose programming language, and it can be picked up very quickly. In fact, Python is so simple to pick up that most programming courses for beginners now use Python programming language to teach fundamentals of programming. Python programs are much shorter and easy-to-write as compared to other programming languages and as a consequence, it has become a preferred choice for a lot of applications. The syntax is much simpler and the code is extremely readable as compared to the same code written in other programming languages.

PHP, on the other hand, wasn’t meant to be a general-purpose language. It was designed specifically for web applications which are definitely more sophisticated than simple, stand-alone programs. As a result, learning PHP has been seen to take more time as compared to learning Python.

Time taken to learn a programming language should be one of the most important factors in choosing which language to pick. For beginners, Python is much easier. PHP, on the other hand, can be a bit tough for novice programmers. PHP was designed to create simple personal pages but off late it has grown in complexity. The PHP developer community is trying hard to provide a lot of support for new programmers. However, as mentioned above, Python wins here by a significant margin owing to the inherent simplicity of the language. The syntaxes and the constructs in Python are amazingly simple to grasp.

Community support

Python and PHP, both have excellent community support. PHP has been in the market for quite a while, particularly for developing web applications. As a result, there is a huge community of PHP developers which is ready to provide support.

Python matches closely here with PHP. There are loads of Python developers in the market who are continuously developing Python applications. As a result, community support is outstanding. Python and PHP are both close here with none of them being a clear winner.

Python became popular when Google started using it for some of the popular Google apps like YouTube. Many powerful startups like Instagram, Pinterest, and Reddit use Python-based web applications. Having said that, it must be noted that the world’s largest social network – Facebook has been written using PHP as the primary backend.

Documentation

Extensive documentation is available for both the programming languages. There are innumerable websites, forums, discussion boards that provide excellent tutorials on how to develop applications using Python or PHP. Competition is stiff here and just like community support, there isn’t really a clear winner. Both languages are equally good in terms of documentation availability.

Pricing

Python and PHP are both completely free and open source. Both win here as well. In fact, both Python and PHP here win significantly over other paid web frameworks.

Library support

Now, this is one point where Python significantly beats PHP. Python has exceptionally well-developed library support for almost all types of applications. PHP lags in this aspect wrt to Python, but Packagist (PHP packages repository) is a strong backbone holding PHP. These days, for instance, a lot of startups and even large organizations are developing Machine Learning backed web applications. Python provides some excellent Machine Learning libraries like TensorFlow, Keras, Theano, Scikit Learn, etc. These libraries are fast, easy-to-use and most importantly, they integrate brilliantly with the web framework. As a result, developing such type of applications using Python is far simpler as compared to almost any other programming language.

Speed

PHP 5.x versions were quite slow, taking a lot of time in execution. However, the new release PHP 7.x is extremely fast, almost 3 times faster than a typical Python program. Speed often becomes an important factor in performance critical applications. For instance, in a core banking system that gets a million hits on a daily basis, a delay of 3 times might create a significant impact on the overall system performance. Therefore, talking about speed, PHP wins by a significant margin over Python.

However, it has to be noted that for most simple applications, the scale is quite low and so, there is not much of a noticeable time lag. For instance, for all practical purposes, 10 milliseconds is not much different from 30 milliseconds given that the application isn’t latency critical.

Choice of Web Frameworks

The most commonly used Python-based web frameworks are Django, Flask, Pylons, Pyramid, etc. On the other hand, the most used PHP based web frameworks are Codeigniter, Zend, Laravel, Symfony, etc.

Django is known to be extremely fast, scalable, secure and easy-to-use. It is quite robust and powerful and is used widely in a large number of applications. Similarly, Codeigniter and Laravel are very widely used in the market and almost all PHP applications today use one of the above 2 frameworks.

Python and PHP are both quite close on this point given that both provide equally good choices. New developers, however, enjoy using Django given that the development time in Django is quite low and it is easy to set up.

Debugging

Python provides a powerful debugger called PDB (Python Debugger). PDB is well documented and is easy to use, even for the beginners. PHP, on the other hand, provides XDebug package for debugging. Both PDB and XDebug provide the most commonly used debugging features – breakpoints, stacks, path mapping, etc. Both Python and PHP are similar here, and none is a clear winner.

To summarize, for most points, both Python and PHP are similar to each other. For others, Python is better than PHP. Python seems to be a winner over PHP. Here is what we would recommend:

  • If you are an experienced PHP programmer, stick to PHP since you already know it in and out.
  • If you are an intermediate programmer, you might want to learn Python and shift to it for better job opportunities.
  • If you are a novice programmer who wants to learn backend development, start learning Python and eventually move to Python-based frameworks.

Related Posts

11 Comments, RSS

  1. Fred October 22, 2018 @ 11:10 pm

    Good write-up.

  2. Larry Garfield October 28, 2018 @ 9:57 pm

    Fact check:

    “PHP, on the other hand, was never meant for novice programmers. It was designed to be used by expert programmers who have extensive programming experience.”

    You clearly have no idea how PHP was developed. PHP succeeded initially precisely because the barrier to entry was so ridiculously low. Any idiot can start writing PHP web sites. (And many did, which is why PHP for a long time had a reputation for bad security; not because the language was insecure, but because so much PHP was written by people with about a week’s experience in coding at all.)

    Friendliness toward novices is a major design goal of PHP, as witnessed by, um, any discussion on the php-internals list about how and if to add functionality. And every presentation ever given by PHP’s founder Rasmus Lerdorf. If anything, PHP was *too* focused on novice programmers in its early years, which resulted in some baggage it still carries around today.

    Strike one.

    “Python has exceptionally well-developed library support for almost all types of applications. PHP comes nowhere close to Python here.”

    May I introduce you to our lord and Savior Packagist.org?

    There are literally tens of thousands of ready-to-use PHP libraries available, and even a standards body (PHP-FIG) that is working to help make them all more inter-compatible all the time. Python certainly has a massive code library of its own, true, but to say PHP doesn’t is simply flat out ignorant.

    The examples you list are all machine learning, advanced-math examples. It’s true that Python’s offering there is stronger, because of tools like NumPy, which are… written in C and bridged into Python. PHP has its own C-based-high-speed library collection (PECL), which does at the moment lack really good advanced-math machine-learning libraries. That’s a fair criticism, but to say that because in that one niche area PHP’s library collection lags that “PHP comes nowhere close to Python” is deliberately and unprofessionally misleading.

    Strike 2.

    Speaking of math, let’s look at your performance section. You say PHP 7 is 3x faster than Python. PHP 7 is also roughly 2x faster than PHP 5. Doing the math, that would mean PHP 5 was 1.5x faster than Python. (I’ve not benchmarked that, but that’s what your numbers imply.) Yet you say:

    “PHP 5.x versions were quite slow, taking a lot of time in execution.”

    If being 50% faster than Python is “quite slow”, then I’d hate to use Python for anything where performance mattered! Again, this is your own numbers, which don’t bear out the comparison you’re making.

    Strike 3.

    “PHP, on the other hand, provides Atom package for debugging.”

    Um. What’s Atom? Isn’t that a code editor? What’s that got to do with debugging?

    PHP’s debugger is called XDebug. If you are talking about debugging in PHP and *not* mentioning XDebug, it clearly shows that you have never actually used PHP, and thus have no business trying to compare it to anything.

    Strike 4.

    “The point to be noted here is that there is no significant point where PHP beats Python.”

    … Except on performance, where just a few paragraphs earlier you say “Therefore, talking about speed, PHP wins by a significant margin over Python.”

    And in the places that you give Python an edge, the only one that isn’t demonstrably *wrong* is availability of machine learning libraries.

    Strike 5.

    Which… isn’t surprising given that you are working at a machine learning startup, and I’ll lay even money are using Django for it. Which is fine; I’ve nothing against Django, Python’s certainly a capable language, and its machine learning libraries really are better than PHP’s options today. You likely make the right decision using it for your machine learning startup.

    But that is no reason to flat out lie about PHP to justify your decision. Your decision to use Python for your startup can and should justify itself; there’s no need to spread FUD about PHP to back it up.

    Please do some research before speaking about things you very obviously know nothing about.

    Signed, the Internet.

    • Hackr Team

      Hackr Team October 29, 2018 @ 1:51 pm

      Thanks for your detailed comments, Larry. Reading your comments, I truly feel that we should have done more homework and dig deeper before publishing the article. We will look into all the points you’ve highlighted and fix the article asap.

  3. Romina October 28, 2018 @ 11:34 pm

    Hey, this is a nice article, but you might want to reconsider the “PHP was designed for experts” bit. PHP was literally created for simple personal pages, and as it evolved, it became a really popular language for begginners because of how easy it was to get started and use it for web pages. I get that you probably feel python is easier, but to rewrite the history of PHP is wrong. It also wasn’t a language that has a history of early “design”, they kind of added things as they needed them for a while, which really shows if you use old PHP functions where the param order and function names were super inconsistent for instance. I can tell you as an experienced PHP developer, I never heard that “PHP was designed for experts” argument before and have to constantly remind people of how far it has come as a language, and how it isn’t just a “small pages” language anymore.

    It really (and sadly) takes legitimacy away from some of the article better points (ie python ML libraries are great, as you say).

    • Hackr Team

      Hackr Team October 29, 2018 @ 1:35 pm

      Very apt points, Romina. I think we went overbroad in mentioning the complexity of PHP. We have fixed it now. Thanks a lot for highlighting this.

      • Bob D. November 2, 2018 @ 2:44 pm

        You definitely didn’t fix it. The entire “Ease of Learning” is just complete nonsense.

        • Hackr Team

          Hackr Team November 2, 2018 @ 8:31 pm

          Ohh, we thought we have fixed it!
          Can you please point out the issues that are still there, Bob? Thanks a lot for your time and help.

  4. Yuri November 6, 2018 @ 7:59 pm

    For me it is interesting to read that “PHP 7.x is extremely fast, almost 3 times faster than a typical Python program” and then “there is no significant point where PHP beats Python”.

    Looks like you haven’t used logic while writing this article :o)

    • Hackr Team

      Hackr Team November 7, 2018 @ 6:37 pm

      This is a valid point, Yuri. We have edited “there is no significant point” part. Thanks for pointing this out.

  5. Kiran RS November 7, 2018 @ 2:36 pm

    This article is not useful because it is total biased. The flwabacks that mentioned on this post may be true in the case of PHP 5.* . Have you tested PHP 7.* .It’s extremely well redesigned one. Also you’re not aware about PHP libraries available un this world. I bet you, python will fail in the number of libraries.

Your email address will not be published. Required fields are marked *

*