Pascal LandauDeploy dockerized PHP Apps to production on GCP via docker compose [Tutorial Part 9] (29.6.2022, 06:00 UTC)

In the ninth part of this tutorial series on developing PHP on Docker we will deploy our dockerized PHP application to a production environment (a GCP Compute Instance VM) and run it via docker compose as a proof of concept.

All code samples are publicly available in my Docker PHP Tutorial repository on Github.
You find the branch with the final result of this tutorial at part-9-deploy-docker-compose-php-gcp-poc.

All published parts of the Docker PHP Tutorial are collected under a dedicated page at Docker PHP Tutorial. The previous part was Create a GCP Compute Instance VM for dockerized PHP Apps.

If you want to follow along, please subscribe to the RSS feed or via email to get automatic notifications when the next part comes out :)

Table of contents

Truncated by Planet PHP, read more at the original (another 108494 bytes)

Link
Matthias NobackNew book: Recipes for Decoupling (28.6.2022, 07:00 UTC)

My new book Recipes for Decoupling is 100% complete and available now!

And now some other news related to this book.

A little background information

My new book is based on two things: 20 years of experience with (mostly framework) coupling issues in legacy code, and the hypothesis that PHPStan, the automated static analysis tool for PHP, can help us keep our code decoupled. Decoupling often means we want to use a dependency, but don't want to couple our code too tightly to it. The process of decoupling often involves some kind of rule, like "don't use Container::get()", but we don't want to focus on this rule all the time, or explain it to new members of the team. Instead, we want a tool that shows you an error when you don't follow the rule. Such an error will break the build of the project and prevent you from ever coupling to a dependency in this specific way again.

The Architecture & Decoupling bundle

Although the book counts 300 pages, it doesn't cover too much theory, and shows a lot of practical code samples instead. You'll learn useful techniques to decouple your code in meaningful ways from frameworks and libraries. Many of these techniques, or recipes, would eventually lead to the discovery of design patterns. In fact, if you already know patterns like Aggregate, or Application Service, you'll quickly recognize them in this book. But this book focuses not on the patterns, but on the question: what's a meaningful way to decouple from the dependencies of my project?

Architecture & Decoupling bundle

Because I still think that it will be interesting to learn about both - using refactoring techniques and static analysis rules to stay decoupled, as well as using design patterns to establish a good architecture for your web applications - I also set up a bundle, providing a nice discount if you buy both "Advanced Web Application Architecture" and "Recipes for Decoupling": the Architecture & Decoupling Bundle.

PHPStan custom rules repository

In "Recipes for Decoupling" we use PHPStan to establish strict rules regarding the use of third-party code or to prevent certain structures in code. We develop these rules step by step and with steadily increasing levels of complexity, but it may be useful to take a look at the end result. For this purpose I've set up a public GitHub repository with the final version of each rule and the corresponding tests:

Interview with Leanpub

If you want to hear more about Leanpub and my experience with book writing on their platform, check out the Frontmatter interview I had with Len Epp recently.

The book

The most important bit: the book. Recipes for Decoupling is 100% done now and available via Leanpub. I will later distribute a paper version via Lulu, but this will take a few more weeks at least.

Link
Larry GarfieldOn the use of Enums (27.6.2022, 15:38 UTC)
On the use of Enums

Enumerations are a feature of many programming languages. However, we should perhaps say "many languages have a feature called enumerations." What that means in practice has a lot of language-specific semantic nuance, and trying to use the feature of one language as though it were the feature of another language can lead to all kinds of broken code. (That's true of most language features.)

So how are Enumerations best used in PHP, specifically? Let's have a look at some examples, and see where they should, and shouldn't, be used.

Continue reading this post on PeakD.

Larry 27 June 2022 - 10:38am
Link
Derick RethansPHP Internals News: Episode 103: Disjunctive Normal Form (DNF) Types (24.6.2022, 08:07 UTC)

PHP Internals News: Episode 103: Disjunctive Normal Form (DNF) Types

In this episode of "PHP Internals News" I talk with George Peter Banyard (Website, Twitter, GitHub, GitLab) about the "Disjunctive Normal Form Types" RFC that he has proposed with Larry Garfield.

The RSS feed for this podcast is https://derickrethans.nl/feed-phpinternalsnews.xml, you can download this episode's MP3 file, and it's available on Spotify and iTunes. There is a dedicated website: https://phpinternals.news

Transcript

Derick Rethans 0:15

Hi, I'm Derick. Welcome to PHP internals news, a podcast dedicated to explaining the latest developments in the PHP language. This is episode 103. Today I'm talking with George Peter Banyard again, this time about a disjunctive normal form types RFC, or DNF, for short, which he's proposing together with Larry Garfield. George Peter, would you please introduce yourself?

George Peter Banyard 0:39

Hello, my name is George Peter Banyard, I work on PHP paid part time, by the PHP foundation.

Derick Rethans 0:44

Just like last time, we are still got colleagues.

George Peter Banyard 0:46

Yes, we are indeed still call it.

Derick Rethans 0:48

What is this RFC about? What is it trying to solve?

George Peter Banyard 0:52

The problems of this RFC is to be able to mix intersection and union types together. Last year, when intersection types were added to PHP, they were explicitly disallowed to be used with Union types. Because: a) mental framework, b) implementation complexity, because intersection types were already complicated on their own, to try to get them to work with Union types was kind of a big step. So it was done in chunks. And this is the second part of the chunk, being able to use it with Union types in a specific way.

Derick Rethans 1:25

What is the specific way?

George Peter Banyard 1:27

The specific way is where the disjoint normal form thing comes into play. So the joint normal form just means it's a normalized form of the type, where it's unions of intersections. The reason for that it helps the engine be able to like handle all of the various parts it needs to do, because at one point, it would need to normalize the type anyway. And we currently is just forced on to the developer because it makes the implementation easier. And probably also the source code, it's easier to read.

Derick Rethans 1:54

When you say, forcing it up on a developer to check out you basically mean that PHP won't try to normalize any types, but instead throws a compilation error?

George Peter Banyard 2:05

Exactly. It's, it's the job of the developer to do the normalization step. The normalization step is pretty easy, because I don't expect people to do too many stuff as intersection types. But as can always be done as a future scope of like adding a normalization step, then you get into the issues of like, maybe not having deterministic code, because normalization steps can take very, very long, and you can't necessarily prove that it will terminate, which is not a great situation to be in. Imagine just having PHP not running at all, because it's stuck in an infinite loop trying to normalize the format. It's just like, oh, I can't compile

Derick Rethans 2:39

Would a potential type alias kind of syntax help with that?

George Pe

Truncated by Planet PHP, read more at the original (another 23817 bytes)

Link
PHP: Hypertext PreprocessorPHP 8.2.0 Alpha 2 available for testing (23.6.2022, 00:00 UTC)
The PHP team is pleased to announce the second testing release of PHP 8.2.0, Alpha 2. This continues the PHP 8.2 release cycle, the rough outline of which is specified in the PHP Wiki.For source downloads of PHP 8.2.0 Alpha 2 please visit the download page.Please carefully test this version and report any issues found in the bug reporting system.Please DO NOT use this version in production, it is an early test version.For more information on the new features and other changes, you can read the NEWS file, or the UPGRADING file for a complete list of upgrading notes. These files can also be found in the release archive.The next release will be PHP 8.2.0 Alpha 3, planned for 7 Jul 2022.The signatures for the release can be found in the manifest or on the QA site.Thank you for helping us make PHP better.
Link
Larry GarfieldBenchmarking Serialization (21.6.2022, 19:42 UTC)
Benchmarking Serialization

I was discussing recently with a TYPO3 colleague about performance, specifically caching. Both he and I are working on systems that may involve hundreds or thousands of objects that need to be cached for later use. The objects themselves are fairly small, but there's a large number of them. The data format is only internal, so we don't need anything standardized or parsable by outside systems.

PHP actually has two options for this use case: serialize()/unserialize() and var_export()/require(). But which is better?

Quick, to the benchmark mobile! The results I found were not at all what I expected.

Continue reading this post on PeakD.

Larry 21 June 2022 - 2:42pm
Link
Evert PotA new OAuth2 client for Javascript (20.6.2022, 19:40 UTC)

Frustrated with the lack of well maintained, minimal OAuth2 libraries, I wrote my own. This new OAuth2 library is only 3KB gzipped, mainly because it has 0 dependencies and relies on modern APIs like fetch() and Web Crypto which are built in Node 18 (but it works with Polyfills on Node 14 and 16).

It has support for key features such as:

  • authorization_code with PKCE support.
  • password and client_credentials grants.
  • a fetch() wrapper that automatically adds Bearer tokens and refreshes them.
  • OAuth2 endpoint discovery via the Server metadata document (RFC8414).
  • OAuth2 Token Introspection (RFC7662).

If your server does support the meta-data document, here’s how simple the process can be:

client_credentials example

import { OAuth2Client } from '@badgateway/oauth2-client';

const client = new Client({
  clientId: '..',
  clientSecret: '..',
  server: 'https://my-auth-server.example'
});

const tokens = await client.clientCredentials();

Without the meta-data document, you will need to specify settings such as the tokenEndpoint and possibly the authorizationEndpoint depending on which flow you are using.

authorization_code example

The authorization_code flow is a multi-step process, so a bit more involved. The library gives you direct access to the primitives, allowing you to integrate in your own frameworks and applications.

import { OAuth2Client, generateCodeVerifier } from '@badgateway/oauth2-client';

const client = new OAuth2Client({
  server: 'https://authserver.example/',
  clientId: '...',
});

// Part of PCKE
const codeVerifier = await generateCodeVerifier();

// In a browser this might work as follows:
document.

Truncated by Planet PHP, read more at the original (another 2436 bytes)

Link
Pascal LandauA primer on GCP Compute Instance VMs for dockerized Apps [Tutorial Part 8] (20.6.2022, 06:00 UTC)

In the eighth part of this tutorial series on developing PHP on Docker we will take a look on the Google Cloud Platform (GCP) and create a Compute Instance VM to run dockerized applications. This includes:

  • creating VMs
  • using a container registry
  • using a secret manager

All code samples are publicly available in my Docker PHP Tutorial repository on Github.
You find the branch with the final result of this tutorial at part-8-gcp-compute-instance-vm-docker.

All published parts of the Docker PHP Tutorial are collected under a dedicated page at Docker PHP Tutorial. The previous part was Create a CI pipeline for dockerized PHP Apps. and the following one is Deploy dockerized PHP Apps to production on GCP via docker compose.

If you want to follow along, please subscribe to the RSS feed or via email to get automatic notifications when the next part comes out :)

Table of contents

Truncated by Planet PHP, read more at the original (another 112295 bytes)

Link
PHP: Hypertext PreprocessorPHP 8.2.0 Alpha 1 available for testing (9.6.2022, 00:00 UTC)
The PHP team is pleased to announce the first testing release of PHP 8.2.0, Alpha 1. This starts the PHP 8.2 release cycle, the rough outline of which is specified in the PHP Wiki.For source downloads of PHP 8.2.0 Alpha 1 please visit the download page.Please carefully test this version and report any issues found in the bug reporting system.Please DO NOT use this version in production, it is an early test version.For more information on the new features and other changes, you can read the NEWS file, or the UPGRADING file for a complete list of upgrading notes. These files can also be found in the release archive.The next release will be PHP 8.2.0 Alpha 2, planned for 23 Jun 2022.The signatures for the release can be found in the manifest or on the QA site.Thank you for helping us make PHP better.
Link
Derick RethansXdebug Update: May 2022 (7.6.2022, 08:13 UTC)

Xdebug Update: May 2022

In this monthly update I explain what happened with Xdebug development in this past month. These are normally published on the first Tuesday on or after the 5th of each month.

Patreon and GitHub supporters will get it earlier, around the first of each month.

You can become a patron or support me through GitHub Sponsors. I am currently 46% towards my $2,500 per month goal. If you are leading a team or company, then it is also possible to support Xdebug through a subscription.

In May, I spend 25 hours on Xdebug, with 27 hours funded.

Development

I continued my exploration of different set-ups that developers use, and have now merged the branch that adds support for the "pseudo-hosts" xdebug://gateway and xdebug://nameserver, which can be used with the xdebug.client_host setting instead of, and in addition to the Docker specific host.docker.internal. This pseudo-host automatically evaluates to the network gateway address, or name server as defined in /etc/resolv.conf, in the container, which will then allow Xdebug to connect to an IDE on the host machine.

I have not figured out how to do it will all different set-ups, so if you have extra information, or if I am still missing set-ups, feel free to comment on the Google Doc.

In the more complicated set-ups, it would likely be easier to use Xdebug Cloud as it has none of these networking complications.

The other big feature that I have worked on is the introduction of the capture of return values while debugging. This feature allows you to step into the "return value from function" phase, where PHP returns a value to the caller function. In this step, there will only be one variable available, which is the return value of that function.

Right now IDEs will have to opt into this new feature, with PhpStorm and the VS Code Plug-in teams confirming that they will make changes for this.

In this GIF you can see how this is useful with fluent interfaces:

Course

I have now recorded the first lesson of the course, and I am editing it with the plan to release this in the next few weeks. It will take a little time, as I need to get into the flow of editing and producing them; and of course, a new web site needs to be constructed as well. Stay tuned!

For further lessons I have started to draft outlines, and they are in different states of completion.

If you want to make sure that the course covers specific tasks that you find hard to do, or what you would like explained, please drop me an email, or leave a comment.

Xdebug Cloud

Xdebug Cloud is the Proxy As A Service platform to allow for debugging in more scenarios, where it is hard, or impossible, to have Xdebug make a connection to the IDE. It is continuing to operate as Beta release. Packages start at £49/month.

If you want to be kept up to date with Xdebug Cloud, please sign up to the mailinglist, which I will use to send out an update not more than once a month.

Xdebug Videos

I have published one new video this month:

You can find all previous videos on my YouTube channel.

Business Supporter Scheme and Funding

In May, no new

Truncated by Planet PHP, read more at the original (another 657 bytes)

Link
LinksRSS 0.92   RDF 1.
Atom Feed   100% Popoon
PHP5 powered   PEAR
ButtonsPlanet PHP   Planet PHP
Planet PHP