You don’t have to venture too far into the technical discussion forums or social media to see developers debating the pros and cons of different programming languages. Two of the titans of server-side scripting are PHP and Perl, so we explore which really is best, and have asked two of our server-side-scripting gurus to give us the low-down:
Senior Principal Engineer at Fasthosts, who’s been a Perl Monger for 20 years.
Developer/Architect turned Product Owner at Fasthosts, who's been a user and advocate of PHP and Perl for 20 years.
Perl vs PHP: which is which?
What is Perl?
Perl, previously known as the ‘Practical Extraction and Reporting Language’, dates back to the late 1980s when it was created by Larry Wall. It was developed and implemented using the C programming language and is well known as being a general-purpose, interpreted language. These days it's got strong cross-platform operating system support, and excellent regular expression support.
Perl has also been called the ‘swiss army chainsaw’ of scripting languages. It’s very flexible and powerful, but can also be an ugly and destructive tool when used incorrectly.
What is PHP?
PHP is also a general-purpose scripting language, originally created by Danish-Canadian programmer Rasmus Lerdorf in the 1990s. PHP originally stood for ‘Personal Home Page’, but these days it’s now a recursive acronym ‘PHP: Hypertext Preprocessor’. It’s used by 78.9% of all websites with a known server-side programming language – almost 8 out of every 10 websites that you visit on the internet are using PHP in some way.
It’s a language that’s easy to learn and, due to its simple HTML integration, is a go-to choice for many developers in web design.
But does it web?
During the heyday of the dot com boom, both Perl and PHP were kings of the web. If a website needed to be dynamic, showing information that was retrieved from a database, your website was likely to use Perl or PHP to present that to the user.
Did I mention that PHP is used by 78.9% of all websites with a known server-side programming language…? - Dan
The difference between Perl vs PHP
Now the introductions are out the way, let’s get down into the details of what the difference is between Perl vs PHP.
Ecosystems and community
Perl's culture and community has developed alongside the language itself. Usenet was the first public venue in which Perl was introduced, but over the course of its evolution, Perl's community has developed a strong love for the language.
Perhaps its greatest asset is the CPAN repository for Perl modules. This community-led project has over a quarter of a million modules, meaning that for any specific task you want to achieve, someone has probably already written a module to help you.
PHP has Packagist and Composer. Packagist is the community-contributed PHP package repository, with over 340,000 packages containing everything from simple and useful polyfils, to serious frameworks like Laravel and Symfony. Composer is the de facto tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you - including those in Packagist.
Performance: the need for speed
As both languages are interpreted, rather than compiled, there is additional overhead during the execution that typically isn't present for programs written in C or C++. Bytecode generation and interpretation, memory management, and dynamic type-checking all add to this. However, this does make them both much easier to debug.
While you wouldn’t use PHP or Perl for nano-second time-critical applications, it doesn’t mean that they’re slow. PHP-FPM and mod_perl have both significantly made usage of these languages for the web better.
The popularity scale
Perl is a fantastic text-manipulation language, syntactically if you’re familiar with C, sed and awk, you’ll find it easy to get to grips with Perl. The dominance of Perl for text manipulation eventually led to other languages and applications offering ‘PCRE’ or ‘Perl Compatible Regular Expressions’.
Due to having different scripting languages capabilities, Perl makes the task of system administration very easy, and this is where it’s still strong today. Although, it has dropped out of favour with younger developers in recent years, and is being taught less in Computer Science degrees, in favour of Python.
Similarly, PHP had encountered a dip in its popularity around its 5.x versions. Until the end of 2009 everything was, but soon after that PHP was going downhill from 10% to 5% market share. By 2014 it had halved again. So what happened to PHP? From its start, PHP was the Visual Basic for web design – easy to learn, easy to deploy. But, it was mainly used by web designers with a limited software engineering background.
The downside of PHP’s simplicity was that it was relatively easy to shoot security holes in it. It’s definitely in a much better place now, fuelled by the rise in popularity of Laravel and the PHP foundation - charged with supporting, promoting, and advancing the PHP language.
Documentation and learning
Languages shouldn’t just be judged on their features, but also on their support, documentation and release frequency.
A significant version of PHP is released each year and is fully supported for two years. During this period, bugs and security issues that have been reported are fixed and are released in regular point releases. After this two year period of active support, each version is then supported for an additional year for critical security issues only.
So which is better?
As always when it comes to technology, the answer is rarely black and white. So, really it depends.
Perl is great for system administration/automation, text processing and data manipulation.
PHP is great for dynamic web pages, API frameworks and being the engine room behind some of the largest hitters on the web like WordPress.
And the winner is...
Both PHP and Perl are excellent languages, with a rich history and excellent community support. But PHP is often the go-to language of the two, being used by over 78% of websites with a known server-side programming language for good reason.