At some point in the past an unfortunate decision was made to store arrays of JSON objects as text files, for maintenance purposes. As the number of files started to grow rapidly, the efficiency of this solution became very low. A better decision to keep them in a NoSQL database was made. And since there was a need to look into the records, the most popular document oriented one was chosen: MongoDB. Now the task was to feed this database with all the stored text files. I have decided to set up a dedicated EC2 instance that will be used for this migration. Below you will find a set of commands that need to be issued in order to have a working PHP & MongoDB stack on EC2.
Recently I was looking for an efficient way to remove an element from a given offset in a given PHP array. And my first thought was to use the array_splice method, but I began to wonder if it is the best option to do so. I searched through the net and I’ve stumbled upon a Steven Vachon’s webpage, where the author compared this option with another one: a combination of unset and array_values methods. His benchmark proved that it was the latter that was over 10% faster. But I couldn’t believe that a combination of two methods will be faster than a single one. So I’ve made my own benchmark.
Programming is a journey which basically never ends. That’s one of the things I like about it. So in order to ride this wave you need to stay on top of it. And there are multiple options for each of us to stay up-to-date with what is going on. Let me tell you what I’ve chosen and how it is going for me.
PHP has two built-in methods which handle MIME base64 encoding and decoding: base64_encode and base64_decode. They assume however that the values that you want to encode or decode are strings. In my recent development it wasn’t the case. The value I wanted to encode and later decode to was integer. How to achieve it with what PHP offers?
Since I have routing rules spread across different config files (one for each application module) I needed to have a single list of all endpoints in my REST server. Something similar to what we can get by running debug:router
on a Symfony console. Here is the sniplet to achieve that.