Xdebug Update: September 2020 – Derick Rethans

Xdebug Update: September 2020

Another monthly update where I explain what happened with Xdebug development in this past month. These will be published on the first Tuesday after the 5th of each month.

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

I am currently looking for more funding.

You can become a patron or support me through GitHub Sponsors I am currently 59% towards my $1,000 per month goal.

If you are leading a team or company, then it is also possible to support Xdebug through a subscription.

In September, I worked on Xdebug for about 60 hours, with funding being around 70 hours. I worked mostly on the following things:

Xdebug 3

This month I mostly focussed on getting Xdebug 3 in shape for a first beta release, with all the new configuration names in place. There are now only a few tasks before I can release Xdebug 3.0.0beta1. I plan to release this around PHP 8.0RC2.

The main changes that I made was to rename the following four configuration settings, mostly to get “rid” of the remote naming:

  • xdebug.remote_hostxdebug.client_host

  • xdebug.remote_portxdebug.client_port

  • xdebug.remote_connect_backxdebug.discover_client_host

  • xdebug.remote_addr_headerxdebug.client_discovery_header

I hope that these new names are easier to explain, and of course the upgrade guide explains the changes too.

Releases

There were two Xdebug releases in September. 2.9.7 changes the step debugger to set up TCP Keepalive probes. This results in better time-out management in case network connections between Xdebug and an IDE drops.

Unfortunately this patch caused compilation issues on FreeBSD where some OS specific flags are different (but the same as OSX, which Xdebug did handle correctly). A fix for this, as well as a fix for path/branch coverage with foreach loops resulted in the 2.9.8 release. I expect to create one more release related to the TCP Keepalive addition as the current release still does not compile for AIX.

Beyond this, I do not expect any more release of the Xdebug 2.9 series unless security or crash bugs are present.

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

PHP 8.0.0 Release Candidate 1 available for testing – PHP: Hypertext Preprocessor

The PHP team is pleased to announce the eighth testing release of PHP 8.0.0, Release Candidate 1. At this time, we’re not planning to adjust the GA date, however this may change during the course of the RC cycle. The updated release schedule can, as always, be found on the PHP Wiki page about the PHP 8.0. For source downloads of PHP 8.0.0 Release Candidate 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 the Release Candidate 2, planned for Oct 15 2020.The signatures for the release can be found in the manifest or on the QA site.Thank you for helping us make PHP better.

PHP 8.0 feature focus: Weak maps – platform.sh

In our last episode, we discussed PHP 8’s new match() expression. Today we look at an edge case feature that will save your edge case.
PHP 7.4 introduced the concept of Weak References, which allow an object to be referenced without incrementing its reference counter. That’s a bit obscure and in practice not all that useful in most cases. What we were really waiting for is Weak Maps, which have landed in PHP 8.

Dynamically changing the log level in Symfony apps – Matthias Noback

This is just a quick post sharing something I was able to figure out after doing some research.

The situation: our application throws exceptions by means of “talking back to the user”.
As developer we don’t want to be notified about all these exceptions.
They aren’t as important as any other exception that should be considered “critical”.
Still, we do want to find these exceptions in the logs, because they can sometimes provide valuable feedback about the usability of the system.

So basically we just want Symfony to log the exception, but dial the standard log level “critical” for certain types of exceptions down to “info”.
Monolog has the concept of a processor for that (represented by the optional ProcessorInterface).
The implemented process() method should return the modified log record, which is actually an array containing the different parts of a log record (the level, the message, and the context).
Since not every log record is related to an exception, we don’t have to do anything in most cases.
Here’s the code:

use Monolog\Logger;
use Monolog\Processor\ProcessorInterface;
use Symfony\Component\HttpKernel\EventListener\ErrorListener;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Throwable; final class AdjustLogLevelForExceptions implements ProcessorInterface
{ public function __invoke(array $record): array { if (!isset($record['context']['exception'])) { /** * Symfony's ErrorListener will provide a Throwable through the log message's context. * If the context has no "exception" key, we don't have to further process this log record. * * @see ErrorListener::logException() */ return $record; } $throwable = $record['context']['exception']; if (!$throwable instanceof Throwable) { // For some reason the provided value is not an actual exception, so we can't do anything with it return $record; } // Change the log level if necessary $modifiedLogLevel = $this->determineLogLevel($throwable, $record['level']); $record['level'] = $modifiedLogLevel; $record['level_name'] = Logger::getLevelName($modifiedLogLevel); return $record; } private function determineLogLevel(Throwable $throwable, int $currentLevel): int { if ($throwable instanceof UserErrorMessage) { // These are exceptions that will be rendered to the user. return Logger::INFO; } return $currentLevel; }
}

Now you only have to register this processor as a service and tag it as monolog.processor:

services: AdjustLogLevelForExceptions: tags: - { name: monolog.processor }

If you use auto-wiring and have set up auto-configuration for the directory where the AdjustLogLevelForExceptions is located you don’t even have to tag this service.
The MonologBundle should automatically do that for you.

PHP 8.0 feature focus: match() expressions – platform.sh

In our last episode, we discussed coming improvements to PHP’s type system. Today we look at a new construct that makes branching logic more powerful.
PHP has had a switch statement since the dawn of time, modeled on the same construct in C. You’ve surely seen it before:
<?php switch ($var) { case 'a': $message = “The variable was a.”; break; case 'b': $message = “The variable was c.”; break; case 'c': $message = “The variable was c.

PHP: file_get_contents with basic auth and redirects – Christian Weiske

I used PHP’s file_get_contents() to fetch the content of an URL:

$content = file_get_contents('https://username:password@example.org/path');

This worked fine until that URL redirected to a different path on the same domain. An error was thrown then:

PHP Warning: file_get_contents(http://…@example.org): failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized

The solution is to use a stream context and configure the HTTP basic auth parameters into it. Those parameters are used for redirects, too.

$user = 'user';
$pass = 'pass';
$opts = [ 'http' => [ 'method' => 'GET', 'header' => 'Authorization: Basic ' . base64_encode($user . ':' . $pass) ]
];
file_get_contents($baUrl, false, stream_context_create($opts));