PHP ::class keyword

According to PHP documentation about the ::class keyword, it can be used for class name resolution: You can get a string containing the fully qualified name of the ClassName class by using ClassName::class. 1namespace NS { 2 class ClassName { 3 } 4 5 echo ClassName::class; 6} 7 8// outputs: "NS\ClassName" It’s handy when you need to pass FQCN around. Some people even started using it to make sure that their code was referencing existing classes. Except that it’s written nowhere in the documentation that this keyword will ensure that the generated FQCN maps to an existing class! ...

January 15, 2016 · 1 min · Kévin Gomez

Why is uniqid() slow?

While profiling RulerZ with Blackfire.io, I noticed that a non-negligible amount of time was consumed by PHP’s uniqid() function. For those who don’t know, this function provides an easy way to generate unique identifiers based on the current date and an optional prefix. Wait, the “current date” part can actually be interesting for our performance issue. What happens if we write something like this: 1foreach ($foo as $bar) { 2 $awesomeCollection[] = new CoolObject(uniqid(), $bar); 3} A simple loop like this should run pretty fast, so if uniqid() simply relies on the current date we should have collisions… but it is not the case. Why? ...

July 26, 2015 · 2 min · Kévin Gomez

Parallel bundle install

In ruby projects, the bundle install command is known to be quite slow. To mitigate this, Bundler provides an option allowing to install gems using parallel workers: bundle install --jobs 4. Just tell Bundler how many concurrent jobs can be launched and let it work.