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.
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.
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
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
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
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!
- Rails Geocoder: A Guide to Managing Locations in Your Apps - June 27, 2019
- PHP vs Python: Which Should You Choose in 2019? - May 25, 2019
- How to Do Authentication Right With Rails Devise - May 21, 2019
- Rails Migration A Complete Guide - May 11, 2019
- Kubernetes vs Docker: How to Choose - May 10, 2019