larry@garfieldtech.comPSR-14: A Major Event in PHP (26.3.2019, 15:44 UTC)
PSR-14: A Major Event in PHP

The PHP Framework Interoperability Group ([PHP-FIG](https://www.php-fig.org/)) has released a number of new specifications in the last year. The latest, [PSR-14](http://www.php-fig.org/psr/psr-14/), covers Event Dispatching. Like many PSRs it's a fairly small spec, at the end of the day, but intended to be high-impact.

In this series of posts I want to cover what PSR-14 is and does (and what it isn't and doesn't), and how to best leverage it in your projects as it gets deployed more widely.

Continue reading this post on SteemIt.

Larry 26 March 2019 - 10:44am
Link
Evert Pot417 Expectation Failed (26.3.2019, 15:00 UTC)

A server emits 417 Expecation Failed when it encountered a Expect header that it didn’t understand or doesn’t support.

A client can use the Expect header to tell the server that it requires a certain behavior from a server.

The only expectation that (as far as I know) is standardized, is 100-continue.

This looks like this:

POST /foo/bar HTTP/1.1
Content-Type: application/gzip
Content-Length: 12345678765
Expect: 100-continue

...

This request intends to upload a large file. The client tells the server that it expects the server to first respond with a 100 Continue response.

If a server supports this, it will first return this 100 Continue response, which tells a client that the request was understood, supported and probably acceptable and it can continue uploading.

If the server did not support this feature, it must response with 417:

HTTP/1.1 417 Expectation Failed
Content-Type: text/plain

We don't support 100-continue

If a server sees a different type of expectation that’s a new future standard, or some custom extension it should always return 417.

References

Link
Voices of the ElePHPantInterview with Amrita Jain (26.3.2019, 11:00 UTC)

This episode is sponsored by

The post Interview with Amrita Jain appeared first on Voices of the ElePHPant.

Link
Remi ColletSmall history about QA (21.3.2019, 15:10 UTC)

Despite I'm mainly a developer, I now use most of my time on doing QA on PHP projects.

Here is, around release of versions7.2.17RC1 and 7.3.4RC1 a report which should help to understand this activity.

 

1. Presentation

Usually, tests are done by PHP developers, particularly thanks to travis and then by users who will install the RC version available 2 weeks before a GA version.

The PHP project follow a release process (cf README.RELEASE_PROCESS) which gives 2 days between the preparation of a version, the Tuesday on git, and the Thursday its announcement in the mailing lists. These 2 days are especially designed to allow the build of binary packages (mostly by Microsoft and often by me for my repository) and to allow a last QA check which mays allow to discover some late issue.

When the new versions were available (on Tuesday afternoon) I start building the packages for my repostiory, givinf more coverage than the current travis configuration:

  • Fedora 27 to 31
  • RHEL 6, 7 and 8-Beta
  • i386 and x86_64
  • NTS and ZTS
  • various compiler versions  (GCC 4 to 9) and system library versions

I also run the build of the 7.3.4RC1 package in Fedora rawhide to trigger the re-build of all the PHP stack in Koschei, one of the CI tools of the Fedora project.

Notice : time to build all the packages for all the targets is about 3h for each version !  (I really need a faster builder).

 

2. Discoverd issues

2.1. Failed tests with pcre2 version 10.33RC1

Already available in rawhide, this version introduce a change in some error message, making 2 tests to fail.

Minor issue, fixed in PHP 7.3+: commit c421d9a.

2.2. Failed tests on 32-bit

In fix of bug #76117 the output of var_export have changed, make 2 tests to fail on 32-bit.

After confirmation by the autor of the change, tests have been fixed in PHP 7.2+ : commits a467a89 and 5c8d69b.

2.3. Regression

Koschei allow to discover very quickly a important regression in the run of the "make test" command. After digging, this regression was introduced in the fix of bug #77609, read the comments on the commit 3ead672.

After discussion between the Release managers, it have been choosen to:

  • revert this change to get back to a sane situation
  • to re-run the release process (new tag onr git)

The version which wil be announced shortly will not be affected byt this regression.

 

3. Conclusion

To ensure of the quality of PHP, of no regression is a complex, long and serious work. Thanks to all the actors, developers, QA team and users, this works pretty well.

So, if you use PHP in a development environment, it is essential to install the RC versions to detect and report us quickly any problem, so we can react before the finale version.

For users of my repository, the RC versions of PHP and various extensions are nearly always available in the testing repositories.

 

Link
Ken GuestUpgrading to PHP 7.1.27 – how to fix the GPG error: https://packages.sury.org error. (21.3.2019, 09:22 UTC)

If, like me, you’re still using PHP7.1, then you should upgrade to the most current security release which is 7.1.27 and was released on the 7th of March. Prior to that we were on 7.1.24 and missed out on fixed for a number of CVEs that were addressed in 7.1.26  and 7.1.25 – and fixes for a segmentation fault or two as well.

This morning, doing this on Debian Jessie yielded the error:

W: An error occurred during the signature verification.
The repository is not updated and the previous index files will be used.
GPG error: https://packages.sury.org jessie InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY B188E2B695BD4743

This is because Ondřej Surý – who maintains the packages there – had to change over to a new DPA signing key as it was present on a server which got compromised.

This means that to install packages from there since the new one was switched to, I needed to download the new key:

# wget -O /etc/apt/trusted.gpg.d/php.gpg href="https://packages.sury.org/php/apt.gpg

After doing that a quick apt-get update set things straight again and apt-get upgrade could then carry on and move things along to 7.1.27.

Realising then that we’d missed out on upgrading to 7.1.27 sooner, I’ve added an additional check to our own product’s status page to determine whether the version of PHP being used is the newest “on-branch” version. It looks something like:


/**
* Get the current/latest version released on branch x for PHP_VERSION.
*
* @param string $version Branch/Version to check for. e.g. 7.1 or 7.1.23...
*
* @return string
*/
function getLatestPHPReleaseOnBranch($version)
{
    $v = explode(".", $version);
    $branch = "{$v[0]}.{$v[1]}";
    $major = $v[0];
    if (extension_loaded('curl')) {
        $url = "https://secure.php.net/releases/active.php";
        $curl = curl_init($url);

        // Use browser's user agent string.
        $agent = $_SERVER['HTTP_USER_AGENT'];

        curl_setopt($curl, CURLOPT_USERAGENT, $agent);
        curl_setopt($curl, CURLOPT_FAILONERROR, true);
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        $json = curl_exec($curl);
        curl_close($curl);
        $decoded = json_decode($json, true);
        $version = $decoded[$major][$branch]['version'];
        return $version;
    } else {
        return null;
    }
}
$latestPHP = getLatestPHPReleaseOnBranch(PHP_VERSION);
if ($latestPHP !== null) {
    $current = PHP_MAJOR_VERSION . "." . PHP_MINOR_VERSION . "." . PHP_RELEASE_VERSION;
    $branch = PHP_MAJOR_VERSION . "." . PHP_MINOR_VERSION;
    echo "Using most recent on-branch PHP release? ", version_compare($current, $latestPHP, "==") ? "Yes" : "No", " (Latest release is $latestPHP Currently on ", PHP_VERSION , ")";
}

Please use this, or something similar, to determine when and if you need to update your PHP install.

Link
Derick RethansPHP Internals News: Episode 2: PHP Compiler and FFI (21.3.2019, 09:02 UTC)

PHP Internals News: Episode 2: PHP Compiler and FFI

In this second episode of "PHP Internals News" we talk to Anthony Ferrara (@ircmaxell) about his PHP Compiler project, and the new FFI functionality that has made it into PHP 7.4.

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.

Credits

Music: Chipper Doodle v2 — Kevin MacLeod (incompetech.com) — Creative Commons: By Attribution 3.0

Become a Patron!
Link
Evert Pot416 Range Not Satisfiable (19.3.2019, 15:00 UTC)

It’s possible for a client to request partial responses from a server. For example, a client might only want the first 5 minutes of a video, or the last 100 lines of a log file.

HTTP clients and servers can do this with range requests.

For example, this request asks for the first 100 bytes:

GET /foo.md HTTP/1.1
Range: bytes=1-100

If a server doesn’t support range requests, it will return 200 OK and returns the entire resource. If it did support range requests, it can use 206 Partial Content and return just what the client asked for.

However, if a client requested a range that didn’t make sense, it can use 416 Range Not Satisfiable to indicate this. For example, maybe a file was 1024 bytes, and the client asked for bytes 2000-3000.

HTTP/1.1 416 Range Not Satisfiable
Content-Range: bytes */1000

References

Link
Voices of the ElePHPantInterview with Ian Littman (19.3.2019, 11:30 UTC)

Show Notes

  • Longhorn PHP
  • Use the discount code elephpant to save $50 off your Longhorn PHP ticket!

This episode is sponsored by

The post Interview with Ian Littman appeared first on Voices of the ElePHPant.

Link
Matthias NobackStyle Guide for Object Design: Release of the PHP edition (19.3.2019, 10:30 UTC)

With a foreword by Ross Tuck

Today I've released the revised edition of my latest book "Style Guide for Object Design". Over the past few weeks I've fixed many issues, smaller and larger ones. Ross Tuck and Laura Cody have read the manuscript and provided me with excellent feedback, which has helped me a lot to get the book in a better shape. I added many sections, asides, and even an extra chapter, because some topics deserve more detail and background than just a few paragraphs. Oh, and Ross wrote the kindest of forewords to kick off the book. It's available in the free sample of the book.

The book will be available at the initial "preview release" price of 20 dollars (with a suggested price of 29 dollars) but only until April 15th. Use this link to apply the discount: https://leanpub.com/object-design/c/PREVIEW_RELEASE.

What happens on April 15th?

Over the past few weeks I've been talking with some fine people from Manning, publisher of tech books. This resulted in a contract with them. They will republish the "Style Guide for Object Design". There will be an e-book, but also a printed version, which is great.

The book currently has code samples in PHP and contains some PHP-specific suggestions, but the Manning edition will have Java code samples, and no programming language or ecosystem-specific advice, hopefully making the book useful and appealing to a larger group of object-oriented programmers. This is an exciting thing for me as a book author, because I may be able to reach more people in this way.

I know that some readers prefer to read the PHP version, so that's why the version as it is now will be available until April 15th. From that moment on, you won't be able to buy it anymore. However, if you've bought the e-book from Leanpub, you will be granted access to the Manning Early Access Program (MEAP) for the book, meaning that you will eventually be able to read the Manning/Java edition too. Once this is possible, I'll send out an email to existing readers, and update the Leanpub page with instructions for joining the program.

Changelog

If you already read (part of) the book, here's a summary of the most important changes, so you can decide if it'll be useful to download and read the new version. The full change log is in the back of the book and it includes linkes to the chapters and sections that have been updated.

  • Foreword

    • Added the foreword by Ross Tuck.
  • The lifecycle of an object

    • Rewrote the explanation about the two types of objects. What really defines these types is how they are related to each other. The first type uses the second type (services versus materials).
  • Creating services

    • Added a subsection: "Keeping together configuration values that belong together", which introduces a way to keep together configuration values that belong together.
    • Added an aside: "What if I need the service and the service I retrieve from it?", which answers a common question that was asked by the technical reviewer.
  • Creating other objects

    • Added a new section: "Don't use custom exception classes for invalid argument exceptions", explaining why you don't usually need custom exception classes for invalid argument exceptions.
    • Added an aside: "Adding more object types also leads to more typing, is that really necessary?", explaining some of the benefits of using object types instead of primitive types, just in case people are wondering if all that extra typing is really necessary.
    • Added another example to the section "Don't inject dependencies, optionally pass them as method arguments", explaining how you could rewrite the currency conversion logic using a simple services. Added a comment about the design trade-offs you have to make in this type of situation.
    • Added an aside about PHP's class-based scoping, explaining how it's possible that a named constructor can manipulate private properties directly.
    • Added a subsection "Optionally use the private constructor to enforce constraints" with an example showing how you can use the private constructor when you have multiple named constructors.
    • Finish the chapter with a new section: "The exception to the rule: Data transfer objects" about Data transfer objects, a type of object with less strict rules, which was not yet discussed in detail.
  • Manipulating objects

    • Added a new introductio

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

Link
Christian WeiskePlay videos from Firefox on your Dreambox (14.3.2019, 15:57 UTC)

Two years after its last release, I finally found the time - and a reason - to rewrite the playVideoOnDreambox browser extension, making it compatible with newer Firefox versions.

The extension adds a button to Firefox that sends the currently playing video to the Dreambox satellite receiver - useful for showing a Youtube video to the family on the large TV screen.

Screenshot

Dreambox' media player does not support playing websites, so the extension needs to extract the URL of the video embedded on the current page. I did not implement this myself, but rely on youtube-dl for this.

Mozilla dropped support for "classic" extensions in Firefox 57; you have to use the "web extension" format now that severely restricts the things you can do. The main problem for me is that extensions cannot execute other programs on the computer anymore (unless the are registered manually with the browser and speak a certain protocol). This broke the my old extension that called youtube-dl directly.

I could have written a youtube-dl proxy script that users would need to register in their browser and that speaks said protocol. But instead I made the Firefox extension rely on the playVideoOnDreambox proxy application, just as the Android app does.

So when your browser shows some video and you click "Play on Dreambox", the extension sends the page URL to the proxy server web app running on some machine in your network. This proxy calls youtube-dl to find the video URL, and then instructs the Dreambox to play the video.

Download

You can download the playVideoOnDreambox firefox extension version 0.6.0 from its homepage or the Mozilla Add-Ons page.

You migh be interested in the playVideoOnDreambox Android app that lets you "share" the video with your satellite receiver.

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