emGee Software Solutions Custom Database Applications

Share this

Planet PHP

People blogging about PHP
Updated: 2 days 17 hours ago

Remove unused "use" imports in PHP - Christian Weiske

Wed, 05/15/2019 - 12:09

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/
Categories: Web Technologies

My Bref Makefile - Rob Allen

Wed, 05/15/2019 - 03:02

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:

Makefile:

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

template.yaml:

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:

template.yaml:

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".

Categories: Web Technologies

Sorting select fields in EasyAdminBundle - Stefan Koopmanschap

Wed, 05/15/2019 - 02:04

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('s.name', 'ASC'); }

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

Categories: Web Technologies

PSR-14: Example - layered caching - larry@garfieldtech.com

Tue, 05/14/2019 - 12:18
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
Categories: Web Technologies

425 Too Early - Evert Pot

Tue, 05/14/2019 - 08: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.

References
Categories: Web Technologies

Changes - Adam Culp

Tue, 05/14/2019 - 06:42

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.

Categories: Web Technologies

Interview with Omni Adams - Voices of the ElePHPant

Tue, 05/14/2019 - 06:05

@omnicolor Show Notes Audio

This episode is sponsored by


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

Categories: Web Technologies

PHP Architect: Serverless PHP With Bref, Part 1 - Rob Allen

Thu, 05/09/2019 - 03:02

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!

Categories: Web Technologies

424 Failed Dependency - Evert Pot

Tue, 05/07/2019 - 08: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: www.example.org 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>

Response:

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

References
Categories: Web Technologies

Xdebug Update: April 2019 - Derick Rethans

Tue, 05/07/2019 - 01:17
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.

Bugfixes

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.

Podcast

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)

Categories: Web Technologies

PHP 7.1.29 Released - PHP: Hypertext Preprocessor

Thu, 05/02/2019 - 17:00
The PHP development team announces the immediate availability of PHP 7.1.29. This is a security release.All PHP 7.1 users are encouraged to upgrade to this version.For source downloads of PHP 7.1.29 please visit our downloads page, Windows source and binaries can be found on windows.php.net/download/. The list of changes is recorded in the ChangeLog.
Categories: Web Technologies

PHP 7.3.5 Release Announcement - PHP: Hypertext Preprocessor

Wed, 05/01/2019 - 17:00
The PHP development team announces the immediate availability of PHP 7.3.5. This is a security release which also contains several bug fixes.All PHP 7.3 users are encouraged to upgrade to this version.For source downloads of PHP 7.3.5 please visit our downloads page, Windows source and binaries can be found on windows.php.net/download/. The list of changes is recorded in the ChangeLog.
Categories: Web Technologies

Pages