Book Image

Mastering PHP 7

By : Branko Ajzele
Book Image

Mastering PHP 7

By: Branko Ajzele

Overview of this book

PHP is a server-side scripting language that is widely used for web development. With this book, you will get a deep understanding of the advanced programming concepts in PHP and how to apply it practically The book starts by unveiling the new features of PHP 7 and walks you through several important standards set by PHP Framework Interop Group (PHP-FIG). You’ll see, in detail, the working of all magic methods, and the importance of effective PHP OOP concepts, which will enable you to write effective PHP code. You will find out how to implement design patterns and resolve dependencies to make your code base more elegant and readable. You will also build web services alongside microservices architecture, interact with databases, and work around third-party packages to enrich applications. This book delves into the details of PHP performance optimization. You will learn about serverless architecture and the reactive programming paradigm that found its way in the PHP ecosystem. The book also explores the best ways of testing your code, debugging, tracing, profiling, and deploying your PHP application. By the end of the book, you will be able to create readable, reliable, and robust applications in PHP to meet modern day requirements in the software industry.
Table of Contents (24 chapters)
Title Page
Credits
About the Author
About the Reviewers
www.PacktPub.com
Customer Feedback
Preface
16
Debugging, Tracing, and Profiling

Preface

The PHP language has been around for quite some time now. What started out as a humble set of scripts, soon turned into a powerful scripting language. The rise of various frameworks and platforms paved the way into the hearts of many developers. Over time, PHP coding standards sprung out, along with numerous testing solutions. These gave it the solid enterprise foothold it has today.

The latest PHP 7.1 release brings forth enormous amount of improvements, both from the language syntax and overall performance perspective. There has never been a better time to dig into a PHP than now.

Throughout this book, we will be covering a wide range of topics. These might seem seemingly random at first, but they reflect a minimum skill level PHP developers are required to possess nowadays.

What this book covers

Chapter 1, The All New PHP, talks about the latest changes introduced to the PHP 7.1 language, most of which directly improve the quality and elegancy of written code.

Chapter 2, Embracing Standards, introduces you to important standards in the PHP ecosystem. Presented standards affect the quality and elegancy of code, pushing ypu closer to truly mastering PHP.

Chapter 3, Error Handling and Logging, stresses on the importance of robust error handling and effective logging. You will learn how to handle errors and log truly important bits of information--two disciplines that often lack proper attention in everyday PHP coding.

Chapter 4, Magic Behind Magic Methods, discusses the magic functions available in PHP classes, and their beauty and importance. You will learn every PHP magic method, and its meaning and use through practical examples.

Chapter 5, The Realm of CLI, explores command-line PHP, and its tools and processes. You will learn how to use Symfony's Console component, work with input/output streams, and handle processes.

Chapter 6, Prominent OOP Features, looks at a subset of features that turn PHP into a powerful OOP language. You will learn important concepts behind PHP OOP features, part of which may escape everyday code base as they find more use as building blocks of various frameworks.

Chapter 7, Optimizing for High Performance, talks about the importance of performance optimization, providing hands-on solutions along the way. You will learn about details of the PHP performance optimization, where small configuration changes can affect the overall application performance.

Chapter 8, Going Serverless, outlines using PHP and its use in serverless infrastructure. You will gain an insight into the emerging serverless architecture, along with utilizing it via two of the dominant PaaS (platform as a service) solutions in the market.

Chapter 9, Reactive Programming, covers the emerging reactive programming paradigm that found its way into the PHP ecosystem. You will learn the basic principles of reactive programming using the synchronous coding techniques to write asynchronous code via icicle, one of the most dominant libraries in the ecosystem now.

Chapter 10, Common Design Patterns, focuses on the subset of design patterns, and the most common ones used in PHP programming. You will learn the practical implementation of several important design patterns, which, in turn, will result in more elegant, readable, manageable, and testable code.

Chapter 11, Building Services, takes you through REST, SOAP, and RPC style services, alongside with the microservice architecture. You will learn how to create a SOAP and REST web server, alongside their respective client counterparts.

Chapter 12, Working with Databases, explains the several types of database PHP programmers need to interact with, such as transactional SQL, NoSQL, key-value, and search databases. You will learn how to query the MySQL, Mongo, and Redis databases.

Chapter 13, Resolving Dependencies, explores the dependency issue and the means to resolve it. You will learn how to solve the dependency issue using the dependency injection and dependency container techniques.

Chapter 14, Working with Packages, covers the ecosystem around PHP packages, and their creation and distribution. You will learn how to find and use third-party packages to enrich applications, along with a quick glimpse of possibly creating and distributing its own packages.

Chapter 15, Testing the Important Bits, dives into several types of testing, emphasizing where one might be more important than the other. You will learn several most common types of testing done for PHP web applications.

Chapter 16, Debugging, Tracing, and Profiling, teaches you the most common tools for debugging, tracing, and profiling PHP applications. You will learn how to utilize several various tools to achieve effective debugging, tracing, and profiling of your application.

Chapter 17, Hosting, Provisioning, and Deployment, discusses making an informed decision for hosting the application, along with provisioning, deployment, and continuous integration processes in place. You will learn about the difference between hosting solutions and the automated process of getting the code from local to production machines.

What you need for this book

Throughout this book, there are a number of simple and self-contained code and configuration examples. To successfully run these, we can easily make use of the Ubuntu powered desktop (https://www.ubuntu.com/desktop) and server (https://www.ubuntu.com/server) machines. Those of you using Windows or OSX machines can easily install Ubuntu within a VirtualBox. Installation instructions for VirtualBox can be found on the official VirtualBox page (https://www.virtualbox.org/).

Who this book is for

Target readers are assumed to be intermediate-level PHP developers. This book will embark you on a journey to become a master in PHP. Solid knowledge of PHP is implied across areas such as basic syntax, types, variables, constants, expressions, operators, control structures, and functions.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "Objects might utilize the PHP Serializable interface, __sleep() or __wakeup() magic methods."

A block of code is set as follows:

interface RequestInterface extends MessageInterface
{
  public function getRequestTarget();
  public function withRequestTarget($requestTarget);
}

 

Any command-line input or output is written as follows:

php index.php
serverless invoke local --function hello

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "We start by clicking the New Project button under the Iron.io dashboard."

Note

Warnings or important notes appear in a box like this.

Note

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail [email protected], and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

You can download the code files by following these steps:

  1. Log in or register to our website using your e-mail address and password.
  2. Hover the mouse pointer on the SUPPORT tab at the top.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box.
  5. Select the book for which you're looking to download the code files.
  6. Choose from the drop-down menu where you purchased this book from.
  7. Click on Code Download.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows
  • Zipeg / iZip / UnRarX for Mac
  • 7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Mastering-PHP-7. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books-maybe a mistake in the text or the code-we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at [email protected] with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.