PHP Releases Fibers 

As a major new update to PHP, version 8.1 introduced several new features to improve the platform while restricting certain functionalities that are considered undesirable. The modern incarnation encourages defensive programming and is a continuation of PHP’s progress in providing type system improvements. This article will explore Fibers and how this functionality will help improve PHP usage going forward.

Php code

What Is Fibers?

Fibers is an innovative new feature included in PHP 8.1 that enables controlled and lightweight currency to PHP. At its most basic level, Fibers is a code block that maintains its own stack and can be terminated, started, or suspended cooperatively by Fiber and the main code. This functionality is available for both variable and state stacks.

Fibers are comparable to “threads” found in any computer program. The OS schedules these threads; however, they do not guarantee when they are paused and resumed. On the other hand, Fibers allow for delicate and precise control of the main program and Fiber execution since they are created, started, terminated, or suspended by the program itself.

One crucial distinction when utilizing Fibers is that concurrent execution does not mean simultaneous execution. Essentially, this means that the update itself will not allow multiple Fibers, or the main thread and a Fiber, to be executed simultaneously. Although, this is a steppingstone for future iterations of PHP frameworks that will be able to manage execution stacks – and allow simultaneous executions effectively.

What Else is New in PHP 8.1?

In addition to Fibers, PHP 8.1 also provides users with multiple other new technologies, including Enums and Type System Improvements. Enums, or Enumerations, is an enumerated type that allows for a fixed number of possible values. One analogy that most people find helpful when talking about Enums is the different suits found in a deck of cards; with PHP 8.1, suits can be enumerated with an Enum.

Among the Type System Improvements, PHP 8.1 also now supports Intersection Types – effectively allowing the declaration of a parameter, property, or return type and the enforcement of any values that belong to a declared class or interface type. This contrasts Union Types found in PHP 8.0, which allow any declared types. PHP 8.1 focuses on “pure” Intersection Types since Union Types, and Intersection Types aren’t allowed in the same declaration.

One final update included in PHP 8.1 is a focus on new hashing algorithms. In this version, support has been added for MurMurHash3 and xxHash. These are among the fastest hashing algorithms, and they can efficiently process data at speeds nearly identical to traditional storage media. With this update, PHP is the first programming language to include these hashing algorithms in its standard library.

Php code developing screen

Final Thoughts

PHP 8.1 establishes over 20 new features that weren’t available in previous versions and brings plenty of changes and deprecations that will transform how PHP developers execute code. While many of these updates are exciting, Fibers should be praised for the vast opportunities it will allow to be creative with coding execution. For a complete overview of the changes introduced in PHP 8.1, I invite you to refer to the expanded documentation found on PHP.Watch.

This is one example of why Maennche Virtual CMO’s software, and experience, are better than most. We are front of the envelope and forward-positioned which allows us to take advantage of these types of advances immediately upon their release. Contact us today to learn how we can help make your software idea come to life!

 

NOTE: PHP 8.1.4 has been released! This is a bug fix, and all PHP 8.1 users are encouraged to upgrade their version as soon as possible. You can find source downloads available directly from PHP.net!

Leave a Comment

You must be logged in to post a comment.