Programming language PHP (page 2/3)

I learned software programming with PHP language. This language evolve a lot and I'm usig it for +20 years. In these posts I'm talking about basic stuff but also some more advanced and ready to use solution, with most of the time real world usage.

Package code in a PHP archive: PHAR

In this article, I show how to group its code in a PHP Phar archive. This step a little complicated, is now greatly facilitated by tools available on Github. I illustrate here, the use of clue/phar-dial.

Use Elasticsearch with Symfony Framework and elasticsearch-php library

Elastic provides a light weight PHP library: elasticsearch-php to connect to Elasticsearch cluster. This Library is an API client with all possible options. It's light weight and lets developer chose implementation to use it. It's a very good alternative to Elastica and his abstraction layer. On this blog I'm using elasticseach-php with Twig to manage my indices and query Elasticsearch.

Control the number of retries of a message with x-death header in RabbitMQ

Sometimes the processing of a message causes an error. In this case, it is common to move this message to another queue to try to process it later. All this, can be automated in RabbitMQ with the DLX / DLK option and the application of a TTL. But be careful not to create an infinite loop of attempted treatment, in this article I will introduce x-death header to control the number of retries.

Manipulation of dates and times in PHP with the DateTime native class

Following the article on the manipulation of dates in SQL, I realized that, in fact, the manipulation of date in php was not so simple and known as that. There are many functions on dates in PHP and I still find a lot of code that gets confused trying to calculate dates with mktime, manipulating timestamps. While a very practical class exists: DateTime. So it is she, and her companions, that I will present.