planet PHP

Subscribe to planet PHP のフィード
People blogging about PHP
更新: 12時間 34分 前

How to build a Docker development setup for PHP Projects [Tutorial Part 3]

2019-05-20(月) 17:07:00

In the third part of this tutorial series on developing PHP on Docker we'll lay the fundamentals to build a complete development infrastructure and explain how to "structure" the Docker setup as part of a PHP project. Structure as in

  • folder structure ("what to put where")
  • Dockerfile templates
  • solving common problems (file permissions, runtime configuration, ...)

We will also create a minimal container setup consisting of php-fpm, nginx and a workspace container that we refactor from the previous parts of this tutorial.

Published parts of the Docker PHP Tutorial

All code samples are publicly available in my Docker PHP Tutorial repository on github. The branch for this tutorial is part_3_structuring-the-docker-setup-for-php-projects.

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 :)


Shout out to Nils Meyer for giving the final "[...] nichts offensichtlich falsch" ("nothing obviously wrong") :)

Table of contents

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

カテゴリー: php

Newcrafts 2019 Day 1

2019-05-17(金) 23:15:00

This week I attended and spoke at the Newcrafts conference in Paris. The following is a mix of notes and personal observations I wanted to share, centered around some of the talks I saw there.

Romeu Romera: Bourdieu's Social theory and our work in tech

I had never attended a talk by Romeu before. I really enjoyed this one. Somehow I already knew that he uses a mindmap to support his talk. I thought he would use an existing mind map to navigate through the talk, but it turned out he was creating one during the talk. For me personally, a slide deck helps to keep track of the story, and it helps me remember all the different topics I need to talk about. Not so much for Romeu, who knew exactly what he was going to talk about, and didn't seem to forget to mention any important part, or make important connections.

The topic is one that seems close to his heart. Still, he called himself "not an expert", saying that this talk was an experiment. It turned out that he was hinting at the fact that the subject matter is vast, and he could only cover some parts of it during the talk. Still, the things he covered, maybe simplified a lot, were very impactful, and very interesting. I'd definitely recommend watching this talk once it becomes available online.

More than with any other talk, I think you can't help it but apply the ideas mentioned to your own situation when you listen to Romeu. He covered three parts of Bourdieu's social theory. The first part is about icons of power. The way you look and behave shows how much power you have. This modified appearance is called Symbolic Violence; an act of violance people in positions of power put onto themselves. I think in the context of conferences, being a public speaker is a great example of violence the speaker puts onto themselves. Personally, I often find it a painful experience (although I'll keep doing it as long as there's a way to help people do a better job in any way).

The second part of the theory has to do with Cultural Capital. Everyone has their own amount of cultural capital. Take for example the people in your team. Some will have more experience than others, a deeper understanding of design, architecture, etc. People with less cultural capital will be seen as lesser people. Having more cultural capital can also be an issue with speakers at a conference, where they will be automatically taken to be experts, to be better humans (or at least, better designers, programmers, etc.). They will be perceived to be more powerful, and more right. This isn't fair to either party; speakers, and attendees alike, but it's how the game gets played.

Differences in the amounts of cultural capital between people will result in Dissociation. The first thing that might happen is that you see a person with less cultural capital as someone you can ignore, not take seriously, etc. The other thing that could happen is that you'll feel that a person with more cultural capital than you is unreachable, and that they wouldn't be interested in even talking to you. Personally I can relate to this problem a lot. When I'm at a conference, it totally depends how I feel: if I feel like I have a sufficient amount of cultural capital, I'll be perfectly fine, and can speak freely with anyone in the room. If I feel that I lack cultural capital, I'm very shy, and generally tend to avoid other speakers, as I will quickly feel like an imposter, noticing a mismatch between the expected and the actual amount of cultural capital.

The third part of the theory is about Hexis, which means something like to what level you feel like you belong somewhere. Hexis could be considered "high" if you never doubt that you should be where you are now. It's low if you have doubts about your presence. Being self-condident is much appreciated, showing doubt is a signal of fragility, and it will look punishable. The immediate association I had, was how code reviews show a difference in seniority (which comes with self-confidence, never a doubt that you're in the right place). The senior developer is likely to provide a lot of nitpicking comments to the one who is more junior. The junior developer will likely have a hard time providing feedback to the senior. The situation gets worse if the senior is considered to be the boss/manager/team lead as well.

And this is where Romeu brings the discussion back to software development. The problem with some agile practices is that they assume equality in the workplace. Pair programming is easy if none of the programmers are the (perceived) boss. Retrospectives are easy if the (perceived) boss isn't there.

If you have enough cultural capital, and symbolic violence, you can ignore the problem. But if you have not, you can't. The problem is real. And of course, it's better if nobody would ignore the pro

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

カテゴリー: php

Command Pattern for Legacy Code Refactoring

2019-05-17(金) 22:49:00

Just recently I run into an issue on one of my projects which I gracefully solved using the Command pattern. The project has a lot of legacy code, and to avoid the pain of major refactoring we do it gradually, piece by piece.

Continue reading
カテゴリー: php

Interview with Phil Jackson

2019-05-17(金) 19:06:00
カテゴリー: php

Remove unused "use" imports in PHP

2019-05-16(木) 04:09:00

To clean up unused namespace imports (use statements) in many PHP files at once, php-cs-fixer (version 2) is of great help:

$ php php-cs-fixer.phar fix --rules=no_unused_imports src/
カテゴリー: php

My Bref Makefile

2019-05-15(水) 19:02:00

In order to use Bref efficiently, I've developed a Makefile so that I don't have to remember all the various commands required. In particular, looking up the correct parameters to sam package & sam deploy is a pain and it's much easier to type make deploy and it all works as I expect.

It looks like this:


# vim: noexpandtab tabstop=4 filetype=make .PHONY: list invoke invoke-local deploy outputs lastlog clean clean-all setup REGION := eu-west-2 PROJECT_NAME := hello-world UNIQUE_KEY := 1557903576 BUCKET_NAME := $(PROJECT_NAME)-$(UNIQUE_KEY)-brefapp STACK_NAME := $(PROJECT_NAME)-$(UNIQUE_KEY)-brefapp # default function to invoke. To override: make invoke FUNCTION=foo FUNCTION ?= my-function list: @$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' invoke: vendor/bin/bref --region=$(REGION) invoke $(FUNCTION) invoke-local: sam local invoke $(FUNCTION) --no-event deploy: sam package \ --region $(REGION) \ --template-file template.yaml \ --output-template-file .stack-template.yaml \ --s3-bucket $(BUCKET_NAME) -sam deploy \ --region $(REGION) \ --template-file .stack-template.yaml \ --stack-name $(STACK_NAME) \ --capabilities CAPABILITY_IAM vendor/bin/bref deployment --region $(REGION) $(STACK_NAME) outputs: aws --region $(REGION) cloudformation describe-stacks --stack-name $(STACK_NAME) | jq '.Stacks[0]["Outputs"]' lastlog: sam logs --region $(REGION) --name $(FUNCTION) geterror: vendor/bin/bref deployment --region $(REGION) $(STACK_NAME) clean: aws --region $(REGION) cloudformation delete-stack --stack-name $(STACK_NAME) clean-all: clean aws --region $(REGION) s3 rb s3://$(BUCKET_NAME) --force setup: aws --region $(REGION) s3 mb s3://$(BUCKET_NAME)

There's three variables that I need to set at the top:

  • REGION – The AWS region. This has to match the Bref layer used in template.yaml.
  • PROJECT_NAME – The name of the project. This is used as part of the S3 bucket and CloudFormation stack names
  • UNIQUE_KEY – A random string to ensure uniqueness for bucket and stack names. I tend to use the current time to the ms, but any string.

I've included a full-cycle set of targets so make setup will create the initial S3 bucket that's required for the project and then make deploy is used to deploy my project.

If I want to start again, make clean will remove the CloudFormation stack and make clean-all will remove the stack and the bucket.

I've also included a few utility targets:

  • make invoke FUNCTION=foo invokes the function foo on AWS.
  • make invoke-local FUNCTION=foo invokes the function foo on sam-local.
  • make outputs displays the outputs of the CloudFormation stack. This is useful for picking up the API Gateway URL for instance, if you set it up in your template.yaml.
  • make lastlog FUNCTION=foo displays the logs for the last invocation of the function foo.
Parameters for template.yaml

I pass the PROJECT_NAME and UNIQUE_KEY through to the template as the parameters ProjectName and UniqueKey respectively. These are then set in the Parameters section of the template:


Parameters: ProjectName: Type: String UniqueKey: Type: String

I then use them in the template when I need uniqueness, such as when creating an S3 bucket:


Resources: ImagesBucket: Type: AWS::S3::Bucket Properties: BucketName: !Join [ '-', [!Ref "ProjectName", !Ref "UniqueKey", "files" ] ]

Which creates a bucket named "hello-world-1557903576-files" which nicely complements "hello-world-1557903576-brefapp".

カテゴリー: php

Sorting select fields in EasyAdminBundle

2019-05-15(水) 18:04:00

I'm currently working on an application using Symfony and their EasyAdminBundle. The experience has been great overall, although there are lots of details and specific usecases that are hard to figure out.

For instance when using relations in your entities and creating the related forms. Select fields for related entities are by default sorted by the key (usually the ID of the related entity), however you'd usually want to sort it alphabetically by the name of the entity. My initial thought was to use the @OrderBy annotation, however that only works for the actual OneToMany relations on the other side of the relation, not on the selectbox for the ManyToOne side of the relation. So that was quickly discarded.

Next up I found that you can do it in Symfony by specifying a query_builder parameter to your form configuration. The downside here is that by default, EasyAdminBundle works with a yaml configuration for your form so that makes it a lot harder to do this. I could do this in an extended AdminController, but that would mess with my form field order.

Eventually, however, I found this comment on Github that gave me the solution. Instead of specifying an anonymous function, you can also specify a static method to be called to fetch the values. And so, my solution was now easily implemented.

In my YAML file, I could now specify the query_builder parameter:

- { property: supplier, label: 'Leverancier', type_options: { 'query_builder': 'App\Repository\SupplierRepository::getSuppliersForSelect' } }

In said repository, I added the specified static method:

static public function getSuppliersForSelect(EntityRepository $entityRepository) { return $entityRepository ->createQueryBuilder('s') ->orderBy('', 'ASC'); }

and now my select field has a nicely alphabetically sorted list of suppliers.

カテゴリー: php

PSR-14: Example - layered caching

2019-05-15(水) 04:18:00
PSR-14: Example - layered caching

So far we've looked at a number of complete, practical examples of using PSR-14 Events in various ways, both conventional and unconventional. In our final (probably) installment, I want to offer a highly unconventional but still practical use of PSR-14 that really shows off just how flexible Events can be: Layered caching.

"But wait, isn't caching the realm of PSR-6 and PSR-16?" Yes. Yes it is. But neither of those offer a built-in way to compose multiple cache backends together. It's certainly possible, but doing so is left as an exercise for the implementer. Let's use PSR-14 to get some exercise.

Continue reading this post on SteemIt.

Larry 14 May 2019 - 2:18pm
カテゴリー: php

425 Too Early

2019-05-15(水) 00:00:00

When a HTTP client makes a connection to a HTTPS server, it uses TLS to create a secure connection. TLS can have a bit of a complicated ‘handshake’ to establish the connection. Because there’s a bunch of back and forward, this can take a long time, especially when there’s a lot of latency between server and client.

There are ways for clients to optimize this setup by sending a bunch of data very early in the process, before the full TLS connection is completely setup.

In some cases this can cause security problems. In those cases a the server can tell the client to retry a specific HTTP request after the TLS connection has been fully set up

In these situations, it will return the 425 Too Early status code.

Normally, you would never have to deal with this status code as a developer, unless you are creating HTTP(s) servers from scratch.

カテゴリー: php


2019-05-14(火) 22:42:00

It was 6 years ago when I was last looking for a change after being a freelancer for a very long time. The idea was simple. I was tired of being the accountant, salesperson, consultant, developer, collections, sysadmin, and more. As a freelance “developer” I had to be all these things to support my family and live in a manner I was accustomed. But I was growing tired of it all, and wanted to have a little more fun by doing the parts I enjoyed most…consulting.

A good friend had been working at a well-known company for about a year and was very happy doing it. He also had grown tired of being a freelance developer, and a job at the company was his answer. So, when I saw an open consulting position on their website, I applied for it.

About a week later I received a call, then went through the typical round of interviews and questions. I was hired!

It was an exciting time, filled with learning new systems, people, and experiences. I was suddenly thrust into meetings with very large companies, and large teams of developers, who needed my help. There were new problems to solve on a weekly basis, and with each problem came new challenges. The number of things I learned during my six years of consulting at the company was mind-blowing, and with each day I discovered there was more and more I didn’t know. I basically went from knowing a bunch of things to village idiot overnight when I was hired.

“I went from knowing a bunch of things to village idiot overnight when I was hired.”

As I transitioned from one customer to another, it also led to traveling quite a bit. I spent half of each year away from home as I went onsite to meet new teams, learn network and application infrastructures, and build relationships with hundreds of people.

I continued to learn a great deal, and with each engagement, I spent less time on search engines and could draw from my own knowledge more often. (Of course, there was still a bunch of searching, but it was less. I’m still the village idiot learning daily.)

As a user group organizer, and speaker, I’ve always enjoyed teaching and sharing, and it was wonderful that my employer encouraged this activity. So I tended to share my knowledge with anyone who would listen, as I began speaking at conferences, user groups, and online from blog posts, podcasts, and videos, as well as through code via online source code repositories.

Through the process, I also did a fair amount of evangelism around products, libraries, and frameworks I believed in and witnessed some real growth from these efforts which drove me to do more.

However, as times change and acquisitions happen, so do the directions companies take. For good, or bad, companies are forced to make decisions and make changes to help them move forward and grow. I’ve witnessed and lived through some events these past couple years that have left me feeling dissatisfied and a little disconnected from the things I’ve come to hold dear.

This doesn’t mean the company is bad. It simply means our paths have diverged for the time being. Therefore, I will be leaving my current employer, as it is time once again for a change.

カテゴリー: php

Interview with Omni Adams

2019-05-14(火) 22:05:00

@omnicolor Show Notes Audio

This episode is sponsored by

The post Interview with Omni Adams appeared first on Voices of the ElePHPant.

カテゴリー: php

PHP Architect: Serverless PHP With Bref, Part 1

2019-05-09(木) 19:02:00

I've written a two-part series on Serverless PHP on AWS Lambda using Matthieu Napoli's Bref for php[architect].

Part one has been published in the May 2019 issue and if you're not already a subscriber, you should be!

If you just want to learn about Bref though, then my introduction to Bref is available for free, just for you!

カテゴリー: php

Interview with Michael Moussa

2019-05-09(木) 18:09:00
カテゴリー: php

Interview with Michael Moussa

2019-05-08(水) 07:38:00
カテゴリー: php

424 Failed Dependency

2019-05-08(水) 00:00:00

The 424 Failed Dependency status-code does not appear in the base HTTP specification, but is part of WebDAV specification, which is an extension to HTTP.

WebDAV has a concept of ‘properties’ that are associated with resources. They are a little bit like extended file attributes, which is a feature on many modern filesystems

WebDAV uses the PROPPATCH HTTP method to update these. Many can be updated in 1 single HTTP request.

Generally HTTP requests are ‘all or nothing’. In other words, they should either completely succeed or completely fail.

WebDAV uses HTTP status codes in response bodies to indicate if a property update was successful or not. If a PROPPATCH was issued, and one property update failed (with for example 403 Forbidden) then automatically every other property update will also fail with 424 Failed Dependency.

424 Failed Dependency will therefore never appear on a HTTP response status line, and only ever in HTTP response bodies that have a 207 Multi-Status response code.

Example PROPPATCH /folder HTTP/1.1 Host: Content-Type: application/xml <?xml version="1.0"?> <d:propertyupdate xmlns:d="DAV:"> <d:set> <d:prop> <d:getcontentlength>1</d:getcontentlength> <d:displayname>Evert</d:displayname> </d:prop> </d:set> </d:propertyupdate>


HTTP/1.1 207 Multi-Status Content-Type: application/xml Content-Length: xxxx <?xml version="1.0"?> <d:multistatus xmlns:d="DAV:"> <d:response> <d:href>/folders</d:href> <d:propstat> <d:prop><d:displayname/></d:prop> <d:status>HTTP/1.1 424 Failed Dependency</d:status> </d:propstat> <d:propstat> <d:prop><d:getcontentlength /></d:prop> <d:status>HTTP/1.1 403 Forbidden</d:status> </d:propstat> </d:response> </d:multistatus>

The above response indicates that getcontentlength was not allowed to be updated, and this caused the update to displayname to fail with 424.

Usage on the web

This HTTP status code should probably not be used outside of WebDAV

カテゴリー: php

Interview with Michael Moussa

2019-05-07(火) 22:08:00
カテゴリー: php

Xdebug Update: April 2019

2019-05-07(火) 17:17:00
Xdebug Update: April 2019
London, UK Tuesday, May 7th 2019, 09:17 BST

This is another of the monthly update reports in which I explain what happened with Xdebug development in this past month. It will be published on the first Tuesday after the 5th of each month. Patreon supporters will get it earlier, on the first of each month. You can become a patron here to support my work on Xdebug. More supporters, means that I can dedicate more of my time to improving Xdebug.

In April, I worked on the following things:

2.7.1 Release

The 2.7.1 release came just at the start of the month, and addressed three bugs:

  • Issue #1641: Performance degradation with getpid syscall, contributed by Kees Hoekzema.

  • Issue #1646: Missing newline in error message.

  • Issue #1647: Memory corruption when a conditional breakpoint is used.

The second bug in the list was more than just a missing newline. Xdebug's handling of connections that were aborted by the IDE was not as good as they could be. For this to be tested, I updated the test harness for remote debugger tests to be able to test for stdout and stderr as well.

I would recommend that everybody to update to this version as the last of these bugs can cause PHP with Xdebug to crash.


Since the Xdebug 2.7.1 release I have worked on a few outstanding bugs that did not make the earlier 2.7 releases.

The remote step debugger allows you to change a variable's value through an IDE. Previously, this would use PHP's internal eval functionality to set the value, except in the cases where the IDE would also associate a new type with the value. I finally switched all code paths of setting new values to use eval. Due to changes introduced in PHP 7, this is now the only reliable way of doing this.

The second issue (#1656) fixes an issue with the step debugger's connect-back functionality. This functionality looks at HTTP headers to find out which IP address to connect to. In some cases, a proxy might inject a second IP address, and Xdebug could not handle this. I improved upon a prototype patch by Florian Dorn to make Xdebug now pick the first IP address in the header that it finds.

Through the implementation of issue (#1615), Xdebug now will turn off Zend OPcache's optimiser when the step debugger is active. The optimiser is really good making crappy code run fast, but it also optimises things away that normal users wouldn't expect, and that then confuses developers single-stepping through their code. Which brings me onto the last point of this update:

Resolving Breakpoints

In last month's update I introduced a new feature that Jetbrains is sponsoring. This issue, #1388: Support 'resolved' flag for breakpoints, is now implemented pending additional testing with a fresh (and experimental) build of PhpStorm. As part of the testing I'm interested in knowing how many breakpoints are usually in use in PhpStorm projects. I would be interested in knowing how many breakpoints, and which types of breakpoints (location, exception), your project has defined. Please leave a note in the comment section if you care to help me out with this.


I have also been continuing with the PHP Internals News podcast. This is a weekly podcast where in 15-30 minutes I discuss new proposed features to the PHP language

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

カテゴリー: php