php

415 Unsupported Media Type

planet PHP - 2019-03-13(水) 00:00:00

When a server receives a request with a body it doesn’t understand, it should return 415 Unsupported Media Type. Most commonly this is a good response for for example a POST or PUT request with an unknown Content-Type header.

The specification says that aside from inspecting the Content-Type header, the server may also return this after inspecting the body.

What this means is that if the client sent a request with a supported Content-Type, it may still return 415 if the contents of the request body were not supported by the server.

For example, a server might support specific JSON bodies, but the contents of the JSON payload didn’t validate, perhaps because it was missing a required property.

However, for the latter case it might be better to use 422 Unprocessable Entity. The description in the standards for 422 is slightly contradicting with the one for 415, but 422 seems to be more specifically for cases where the Content-Type was correct, the request was parsable, but semantically incorrect.

I would suggest the following approach to deciding the right status code:

  • If the Content-Type was not supported, use 415.
  • Else: If the request was not parsable (broken JSON, XML), use 400 Bad Request.
  • Else: If the request was parsable but the specific contents of the payload were wrong (due to validation or otherwise), use 422
Example POST /new-article HTTP/1.1 Content-Type: text/html <h1>Another day, another blog post</h1> HTTP/1.1 415 Unsupported Media Type Content-Type: application/json {"error": "This endpoint only supports text/markdown for new articles"} References
カテゴリー: php

Web Summer Camp 2019

php.net - 2019-03-12(火) 20:48:51
カテゴリー: php

Interview with Keith “Danger” Casey

planet PHP - 2019-03-12(火) 20:30:00

@caseysofyware Show Notes

Audio

This episode is sponsored by


The post Interview with Keith “Danger” Casey appeared first on Voices of the ElePHPant.

カテゴリー: php

Laracon EU 2019 Madrid

php.net - 2019-03-12(火) 02:28:17
カテゴリー: php

Laracon EU 2019 Amsterdam

php.net - 2019-03-12(火) 02:26:39
カテゴリー: php

Bulgaria PHP Conference 2019

php.net - 2019-03-10(日) 17:32:05
カテゴリー: php

WordPress and HTTPS-terminating proxies

planet PHP - 2019-03-09(土) 20:15:00

A blog I am writing for was looking for a new place to host their website. Since we have a nice cluster with Rancher up and running, I offered to host the site. It's WordPress, so PHP, so how hard could it be, right?

I spent quite a few hours migrating everything. The initial migration to Docker was not that hard. There is a great official WordPress image for Docker, which makes it extremely easy to set up a new WordPress site in Docker.

The next thing is handling file uploads. Using the do-spaces-sync plugin this was easily set up to use DigitalOcean Spaces. It took a while to upload all images from the old wp-content/uploads to Spaces, but once that was done, I had it working immediately after setting it up. So far, this whole migration was a breeze.

Until I flipped the switch on the DNS and pointed it to our new hosting. I immediately got caught in an infinite redirect loop, and I had no idea why. I've spent hours turning off plugins, turning them on again. Debugging everything, watching logs. I could not figure it out. In the headers I did find a header saying that the redirect came from WordPress:

X-Redirect-By: WordPress

Eventually, I tried explaining the problem in the #wordpress channel in the PHPNL slack and as I'm typing my explanation something dawns on me...

Our Rancher setup has a load balancer that terminates the HTTPS then forwards an internal request to the container using http. But in WordPress, I have configured the siteurl to be https://. So WordPress gets a request using http, figures out it should be using https, and redirects. This causes the infinite redirect loop!

Of course, I wasn't the first to encounter this problem. Once I know what the problem was, searching the Internet quickly gave me the solution. In Wordpress Codex of course. The only thing I needed to do was add a single line to my .htaccess file:

SetEnvIf X-Forwarded-Proto https HTTPS

Once I did that, rebuilt my containers and deployed them to Rancher, the problem was solved. All of a sudden, everything worked.

カテゴリー: php

New domain

planet PHP - 2019-03-07(木) 23:10:00

I've had the domain leftontheweb.com for ages. It's been with me since 2004. However, since I recently got a brand new .dev domain, I decided it was time for a change. Since I can't even remember how I came up with the old name, it's time for a change. A new name that is easy to recognize, easy to remember and easy to link to me.

The new domain name for this blog is:

skoop.dev

It only makes sense to switch to this domain. Skoop has been my nickname for as long as I have access to the Internet. And since my main occupation is still development, this switch makes sense.

Now, to find interesting topics to blog about again...

カテゴリー: php

PHP 7.1.27 Released

php.net - 2019-03-07(木) 20:49:58
カテゴリー: php

PHP 7.2.16 Released

php.net - 2019-03-07(木) 19:08:52
カテゴリー: php

PHP 7.3.3 Released

php.net - 2019-03-07(木) 18:10:40
カテゴリー: php

PHP 7.2.16 Released

planet PHP - 2019-03-07(木) 09:00:00
The PHP development team announces the immediate availability of PHP 7.2.16. This is a security release which also contains several minor bug fixes.All PHP 7.2 users are encouraged to upgrade to this version.For source downloads of PHP 7.2.16 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.
カテゴリー: php

PHP 7.1.27 Released

planet PHP - 2019-03-07(木) 09:00:00
The PHP development team announces the immediate availability of PHP 7.1.27. This is a security release which also contains several bug fixes.All PHP 7.1 users are encouraged to upgrade to this version.For source downloads of PHP 7.1.27 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.
カテゴリー: php

PHP 7.3.3 Released

planet PHP - 2019-03-07(木) 09:00:00
The PHP development team announces the immediate availability of PHP 7.3.3. 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.3 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.
カテゴリー: php

Interview with Jeremy Lindblom

planet PHP - 2019-03-06(水) 21:00:00

@jeremeamia Show Notes

Audio

This episode is sponsored by


The post Interview with Jeremy Lindblom appeared first on Voices of the ElePHPant.

カテゴリー: php

414 URI Too Long

planet PHP - 2019-03-06(水) 00:00:00

The URI or path of a HTTP request doesn’t have any hard limits in terms of how long it’s allowed to be.

However, Browsers and search engines have limits, and on the server side it’s a good idea to limit the length of the URI to combat certain denial-of-service attacks or bugs.

Based on limits of browsers, it’s a good idea to try and not exceed 2000 bytes for the uri.

When a client does exceed it, the appropriate status code to return is 414 URI Too Long.

Example HTTP/1.1 414 URI Too Long Content-Type: text/html <p>Insufficient level of conciseness in request</p> References
カテゴリー: php

Retiring PHP's Mirror Program

planet PHP - 2019-03-05(火) 23:15:00
Retiring PHP's Mirror Program
London, UK Tuesday, March 5th 2019, 14:15 GMT

The PHP.net website has in the last 20 years made use of an extensive network of mirrors to make the PHP documentation available, and distribute source tarballs. These mirrors have been maintained by members and companies in the PHP eco-system for many valuable years. However, the administration of the mirror system is often haphazard, with few contributors helping out—PHP is Open Source, and this is simply how these things can go.

Maintaining the mirrors is now no longer sustainable, and also hinders the take up of moving the PHP.net website fully to HTTPS. Because the PHP.net team has no access to the mirror servers, we also can't make sure the mirrors are up-to-date, and some mirrors are still running PHP 5.3.

It is likely no longer necessary to have a mirror system in place, as unlike 20 years ago, it is not nearly has hard as setting up a distributed cache system. As a matter of fact, some of the PHP.net web site, through http://www.php.net/, already sits behind a Content Delivery Network (CDN) from Myra, which is sponsored by long time PHP contributor Sascha Schumann.

With these preliminaries out of the way, I would therefore like to announce the discontinuation of PHP.net's mirroring program. Instead of having mirrors, we are moving all of PHP.net to HTTPS (and get rid of https://secure.php.net), and move them behind Myra's CDN, with the same local content delivery opportunities, but at significantly less administration requirements.

Watch this space for further developments!

To end this post, I would very much like to thank all the mirror maintainers for their dedication, time, and bandwidth over all these years. Thanks!

カテゴリー: php

Croissants in Québec

planet PHP - 2019-03-05(火) 16:00:00
カテゴリー: php

ページ