Archive September 2023


How to cache Symfony responses with Cloudflare for free

Caching is a great way to speed up your website and reduce your server load. Why waste energy on pages that rarely change?

ElasticSearch fix 406 Not Acceptable: error

I'm trying to index a document with ElasticSearch PHP client (version 8.8), and I'm getting an error when trying to execute the create document request:

406 Not Acceptable: {"error":"Content-Type header [application/vnd.elasticsearch+json; compatible-with=8] is not supported","status":406}

The weird thing is that the client allowed me to create an index, but when I tried to index a document, I got an error...😕

My configuration is:

  • ElasticSearch PHP client: version 8.8
  • ElasticSearch server: version 7.10

How to return JSON response from Symfony Controller

To return JSON response from Symfony Controller, you can use the $this->json(); method or new JsonResponse(['...']);

JSON (JavaScript Object Notation) is a lightweight data interchange format commonly used for transmitting and storing structured data. It consists of key-value pairs and arrays, making it versatile for representing various data types in a human-readable format that can be easily processed by computers. It is widely used in programming and especially in APIs.