Getting to Know PHP
On the pretext of knowing me and knowing you, you have been lured into writing your first PHP script in the previous session. Now that you have gotten your feet wet, there is no looking back.On the pretext of knowing me and knowing you, you have been lured into writing your first PHP script in the previous session. Now that you have gotten your feet wet, there is no looking back.
In this lesson, you will get to find out what PHP is, why PHP is use, and how PHP works.
What is PHP?
Is PHP an acronym? You bet! But don’t bother. However, if you insist, PHP is a recursive acronym for PHP: Hypertext Preprocessor.
PHP is one of the most widely used open-source server-side scripting languages for web development. Many popular websites are powered by PHP. These include WordPress, Wikipedia, Facebook, among others.
Why use PHP?
Apart from the distinct role and characteristics as server-side scripting language, some of the other reasons to use PHP for server-side scripting include:
- PHP is a free language with no licensing fees so the cost of building a website using PHP is cheaper.
PHP can be used on all major operating systems, including as Linux, Unix, Microsoft Windows, Mac OS X, and many others.
PHP can run on cloud computing platforms, including Azure App Services and Amazon EC2.
PHP supports a variety of web servers, including Apache, IIS, lighttpd, and nginx.
PHP supports a wide range of databases, including MySQL, MSSQL, SQLite, MongoDB, PostgreSQL, IBM DB2, and many others.
Last but not least, PHP has very good online documentation, and countless forums and tutorials, which make learning and using the language relatively easy as you can always find help online easily whenever you hit a snag.
How PHP Works?
Having learned the usefulness of PHP in web development, let’s find out how PHP works through an example which also serves to illustrates some of those differences between client-side scripting languages and server-side scripting languages mentioned earlier.
.php, say example.php, and be placed in the web directory of a web server. You can request this file from the web server by typing the URL of this web server in a browser. To emulate this process, copy the code under the example.php code section to the Editor of the PhpFiddle widget, then hit the
What has happened is:
- Server side: when the web server receives a request for example.php (emulated by hitting the
Runbutton of the PhpFiddle widget), a PHP interpreter, which is implemented as a module in the web server, picks up the PHP code inside the pair of
Wait a minute, where is the PHP code? No PHP code, only the result of its processing, i.e. the date and time of the server, was returned to the client side.
Points of Interest
The key takeaways from this lesson are:
- PHP is a server-side scripting languages.
PHP is used to perform business logic computation.
PHP can access server resources such as databases, files, web APIs, etc.
PHP files have