Tech Review Series: PHP

If we talk about working with databases and creating dynamic web pages, PHP is among the first scripting languages to come to mind. It is one of the most used languages for backend development and is versatile enough to be used for various applications in addition to dynamic content creation.

In this article, we will talk about PHP and why you should not compare Node.js and PHP when it comes to server-side development. We will also cover the main areas of PHP usage – and you’ll be surprised to find out about them!

Tech Review Series: PHP

PHP: a brief history and the current state

Like other great things, PHP was created by chance. Rasmus Lerdorf, its creator, simply wanted to track the visits to his online resume. So he wrote a set of CGI binaries in the C language and called it “Personal Home Page Tools” (or PHP Tools for short). After some time, Lerdorf decided he needed more functionality so he rewrote PHP Tools and significantly expanded it. This was the start of PHP development towards its current state.

A funny thing about PHP development is that PHP was not designed intentionally as a programming language but it grew organically instead, with Lerdorf adding new functionality and expansions “on the go”. Such an approach led to inconsistent functions naming and inconsistent ordering of the functions’ parameters.

The first official version of PHP (the abovementioned PHP Tools) was released in 1995. Javascript was announced as a client-side language and was released in 1996. In the following three years, PHP has seen many modifications and changes and in 1998, the PHP 3 version was released. PHP 3 resembled PHP that we know today and gained immense popularity due to its functionality. This version had strong extensibility features,  OOP support, consistent language syntax, and a very mature interface for various databases.

PHP 4 was introduced in 1999 and the PHP 5 version was released in 2004 only. In 2005, Andrei Zmievski and his team tried to incorporate native Unicode support into the PHP but the project did not succeed and the team had to roll back to the non-Unicode version of the language.

By now, the latest version of PHP is PHP 8, released in November 2020. Even though some people consider that PHP has no future, it’s still going strong. By now, it’s used by 79.1% of websites and displays a steady usage rate if looking at historical trends. The companies that use PHP include Zoom, Microsoft, WordPress, and Washington Post, and the language remains relevant and in high demand.

PHP: technology type

PHP is an open-source scripting language used to create dynamic web pages. Even though scripting languages belong to the group of programming languages, there is a major difference between them: scripting languages do not need to be compiled and are interpreted instead. This has a slight impact on the performance as compiled languages tend to run faster (though interpreted languages have easier debugging).

In addition to creating dynamic web content, PHP also helps manage databases, track sessions, perform system functions, and encrypt data. As for the most notable PHP features, they are:

  • Case sensitive: “var” will not be the same as “VAR”, for example.
  • Support for many major protocols: LDAP, POP3, IMAP.
  • Integration with the most popular databases: Oracle, MySQL, Sybase, PostgreSQL.
  • Compatibility with almost all servers,
  • Built-in support for MySQL.

PHP Composer

PHP Composer is a tool for dependency management (similar to npm in Node.js). The Composer significantly facilitates working with the libraries since it’s capable of installing and/or updating them for you, once you declare them.

For example, you have a project that depends on a few libraries and some of these libraries depend on other libraries in turn. Sounds a bit confusing, doesn’t it? What Composer does is allowing you to declare the libraries that you depend on – and then it does all other work, such as determining the needed versions to be installed and installing them. And the best thing is that you can update all your dependencies in one command only.

It is important to note though that Composer installs the necessary libraries on a per-project basis, right in a directory inside a project. With Composer, you can use different versions of one library across various projects but it’s not recommended to install the libraries globally.

The use of PHP: most common cases

PHP is known for creating dynamic web pages but that’s not everything it is capable of doing. If you dig deeper, you’d be amazed by the possible PHP applications in the world of software development.

Web security

Security should be the top priority for any software product and PHP can successfully provide it. Here are some PHP applications in terms of security:

  • User and password authentication: PHP is capable of storing and retrieving the login data from the database with the help of top-level encryption.
  • Cookie authentication and session management: handled with the help of PHP Sessions.
  • Two-step verification: since PHP can generate a secure random token (and securely store it in the database) and can safely share it between the user’s mail and the API service.
  • Data encryption: PHP can encrypt the data which, without a doubt, is a big advantage in terms of security.

Work with WordPress

Since most CMS and web frameworks are written in PHP, it makes sense that this language is great for work with WordPress and its plugins.

WordPress is one of the most known and popular CMS in the world and most of its core files are in PHP. That means, almost any theme or plugin that you install will most probably be PHP as well. Therefore, if you work with WordPress and want to tweak or extend its functionality, it makes sense to use PHP for that.

PHP Pros and Cons

PHP has a number of impressive benefits that it brings to backend development. At the same time, it has several flaws that sometimes impact the developer’s decision about which language to choose. See the table below to learn about the most distinct.

Pros

A variety of available libraries and frameworks: helps to design well-structured applications
Big community and a large number of developers
A large base of reference and educational materials: could be extremely helpful for configuring and implementing solutions
Multiple options for database connectivity: supports almost all databases, and object-relations mappers makes working with them easy
Inexpensive website hosting
Time to market: is significantly reduced
Open-source: easily adjusts to modern needs

Cons

Decreasing popularity
Inconsistency: sometimes, even simple functions can surprise you in terms of performance  
Interpreting language: may be slower than its compiling alternatives
Weak typization: could lead to unexpected errors
Too many configuration files: can impact code behaviour
Hard to debug
Behavior depends on a platform: the same code could provide different results depending on a PHP version or environment configuration

Expert Opinion

Many websites use PHP and there are many great solutions out there. E-commerce stores, blogs, forums, extensive database support – you can get all this out of the box. And if you want to build a complex, stable, and specific product, you can use a PHP framework such as Symfony or Laravel. These frameworks are well-organized and well-documented, contain built-in abstraction components, support unit testing, and have web security features like CSRF and SQL injection protection.

A low entry threshold is both an advantage and a disadvantage of PHP. On one hand, you can quickly figure out a certain part of an application, change it, and it will work. On the other hand, the behavior of the language is often not very obvious so it might be confusing for beginners.

PHP is constantly evolving and has already seen numerous changes and improvements. Unfortunately, the behavior of the code in different environments is not unambiguous. I recommend using Docker to create the environment so that the code execution results are the same on all platforms.

PHP is not the best choice for continually-running or heavy processes. You could increase memory_limit and max_execution_time but PHP processes are meant to die sooner or later. There is always a workaround to speed up a script execution (APCu, OPcache, HHVM, Memcache) but it will probably cost you hours (if not days).

Summing up, PHP was designed for and works very well with web applications. It is a great prototyping tool that will get you a working product in no time. PHP can be used in complex, heavy-loaded systems, but, of course, it requires experienced specialists and non-trivial solutions sometimes.

.Net developer at SoftTeco

Igor Maslakoff

Conclusion

Even though some developers consider PHP to be outdated, the language is still widely used by both industry giants and smaller companies. Once you learn your way around it, PHP becomes a powerful and robust tool for working with the backend part of your project.

The next article from our tech review series will cover the Go programming language and it will be the last article on the subject of backend development. But don’t worry – we will continue our series with front-end development so sign up for our newsletter and stay tuned!

Want to stay updated on the latest tech news?

Sign up for our monthly blog newsletter in the form below.

Softteco Logo Footer