PHP vs. Python: Which Should You Choose in 2019?

PHP vs Python: Which Should You Choose in 2019?

Eric Boersma Developer Tips, Tricks & Resources

There are dozens of great languages to learn. Today we’ll be breaking down the differences between two of the best: PHP vs Python. Which one is best for your application? Which is going to give you the best return on your development time?

We’ll pit these two head-to-head and find out which is the best choice for you.

Ease of Installation

If you’re building a small application by yourself, PHP has three simple advantages.

Installation is a breeze. It runs well on Windows (native or WSL), OS X, and Linux, and can be found on a variety of shared hosting sites around the world, usually for a minimal fee.

Installing Python can be a difficult proposition. If you’re on OS X, there’s an existing system version of Python that came installed on your computer.

Bad news.

It’s outdated and not suitable for application development.

Trust me, you don’t want to install new packages on the system Python. You’ll need to install a new version to make sure your system is as stable as possible.

Python on Windows can also take a bit of work to install.

The most common advice is to use a Windows package manager like Chocolatey as you start out. If you’re planning for a team, that little bit of extra work can add up.

If your team’s on Linux, though, you’ll have no problems installing Python.

PHP wins this round on account of being easier to install pretty much everywhere.

Score: PHP 1, Python 0

Library Management

Python has a strong advantage over PHP.

Python uses Pip (a recursive acronym that stands for “Pip Installs Python”) to manage packages. Pip makes managing different libraries within a Python application simple, it’s fast, and your project’s requirements are easy to parse at a glance. As a Python developer, Pip is an essential tool to have in your toolbag.

PHP’s library management isn’t as strong.

PHP 7 introduced Composer, which is a fantastic tool, mostly feature complete, and (when paired with a tool like Packagist), you’ll find package management close to on-par with Python’s. Unfortunately, it’s still pretty young.  

At the end of the day, Python has a broader variety of mature packages, and their tools are a bit easier to install and use at this time.

One point for Python.

Score: PHP 1, Python 1

PHP Retrace

Environment Management

If you build your applications entirely on containers using something like Docker, you probably don’t need to worry about environment management. So, congratulations! Move right along.

If that doesn’t describe you though, being able to segregate your application’s installed language and library versions is a critical part of staying sane as a developer.

Python, again, has a best of breed application to manage environments. Virtualenv is a system used to install multiple versions of Python side by side and switch between them quickly. Virtualenv is one of the original environment managers and has been actively maintained for more than a decade. It’s a terrific piece of software.

PHP isn’t so lucky. There is an analog for virtualenv for PHPcalled virtPHP,. but that project has been archived and is no longer actively maintained. Their own developers actually suggest using containers instead.

This is wise advice as containers have all sorts of advantages for developers and operational deployment. Unfortunately, they’re not a great fit for every environment. If your environment is one of those, PHP is at a disadvantage here.

Python scores another point.

Score: PHP 1, Python 2

Easy to Learn

Python and PHP are very similar. Both are object-oriented interpreted languages that run on a variety of operating systems. They’re both dynamically typed and have terrific IDE support. Lastly, Python and PHP both stand out in the world of syntax.

PHP requires that you prefix all variables with a $ sign, and uses the -> operator to indicate a method called on an object. Those make it stand out from other C-style languages.

Python’s syntax is dissimilar from many other languages. It disposes of curly braces and instead it embraces whitespace sensitivity.

So, which is easier to learn?

That’s tough to say.

PHP has some advantages. PHP has a double-edged sword in their array concept, which serves as something like a combination between Python’s list and dictionary data types. It’s a benefit because if you understand how to use an array, you can do a lot in PHP. However, it’s also a negative because PHP often lacks quality implementations of other more focused data types.

If you’re trying to do something that doesn’t fit into an array, using PHP means you might need to write your own data type.

In Python, that’s not the case.

Python has a wide variety of built-in data types that are ready to go right out of the box. The challenge with Python is often knowing which tool to use for the specific job that you’re doing. That’s still a challenge, but it’s usually an easier one to solve. Python does have a disadvantage that the Python 2 to Python 3 transition has not been backward compatible.

One more quick word about learning PHP: it’s an old language. That means there are a lot of outdated, and frankly bad, tutorials out there. That’s a real impediment to learning the language from scratch.

Despite that, both score in this category.

Score: PHP 2, Python 3

Application Speed

Many of the things that make web applications slow aren’t related to programming languages at all. Slow database queries bog down every programming language. Relying on excessive network queries or reading a lot of information from a disk will slow you down every time. That said, in most circumstances, PHP is a faster programming language than Python.

The core PHP team has done a great deal to speed up PHP, and with PHP 7, they succeeded.

That evaluation doesn’t come without caveats though. PHP famously restarts your entire application every time a web request starts. For the most part, that’s not a problem. However, it can be trouble if you’re working with an application that needs to share resources across requests.

Because PHP sets up and tears down the entire application on every request, sharing resources can be difficult. That’s not as much of a problem for Python, and in fairness, it’s something that most web applications don’t need to do.

It’s also important to remember that no matter the language, you’re not guaranteed a fast web app. If you’re building a new web application and you’re looking for the best performance, you should plug into a tool like Retrace. It’ll help you identify problem spots within your application and speed them up no matter which language you choose.

PHP gets the point here.

Score: PHP 3, Python 3

PHP vs Python Conclusion

We’ve got a tie! Honestly, that feels about right. Both PHP 7 and Python 3 are excellent choices for building a web application in 2019.

So, when comparing PHP vs Python, which should you choose? Well, that depends on what you need.

Do you need to share environments on the same PC? Python is almost certainly the right answer. Are there developers on your team who already know some PHP? PHP is probably your best bet! Does your application require great Unicode support? Python would be the way to go.

No matter which way you go, it’s not about PHP vs Python. The key is to get out there and get building. You can’t make a wrong decision here. Best of luck building your new application!

Schedule A Demo

About Eric Boersma

This post was written by Eric Boersma. Eric is a software developer and development manager who's done everything from IT security in pharmaceuticals to writing intelligence software for the US government to building international development teams for non-profits. He loves to talk about the things he's learned along the way, and he enjoys listening to and learning from others as well.