Posts

Showing posts with the label laravel

Redis smooth throttling

Image
This might be an edge case and not even complicated, but I thought I'd share it. So, I had this use case recently where I needed to throttle email send out speed, while allowing to control it on admin panel. However, the difference from the usual case was that you don't enter for example how many emails to allow per minute or second, but you enter over how long the hole process should be done. So, for example, send all ~1k emails over 1 hour. Luckily, laravel has redis throttling built in. We can utilize it like so: <?php Redis :: throttle ( 'key' ) -> allow ( 1000 ) -> every ( 3600 ) // 1 hour -> then ( function () { /* send */ }, function () { /* release */ }); But, here lies the problem. In this case it will send all that 1000 emails as fast as possible. It might take only a couple of minutes. If you have more than 1k emails, the queue will wait for the remaining time, do nothing, and then after 1 hour will send a bunch of ...

Fast PHPUnit tests

Image
Testing your software is an important process. If you don't test, then you're falling behind your colleagues and cause a potential danger to your and your company's reputation and money. So, if you haven't started already, start now. Don't worry, it only looks confusing at first, but once you get used to it, you won't imagine working without testing. Your end-goal is to feel uncomfortable if you push untested code. Nonetheless, this post is about how to make PHPUnit tests faster. Since I'm mainly a Laravel developer, I will focus on this framework. However, everything can be easily adapted to use on other frameworks as well. It is nothing new or revolutionary, but I still sometimes see people running tests the hard and slow way. So here are the things you can do to speed up your tests. Use SQLite Many still use MySQL database for their tests. This is might look fine with a few tests, but as your application grows running your tests becomes a very l...

Taking Laravel certification exam

Image
So... I had recently taken a Laravel certification exam and would like to share my experience and maybe help you decide on taking it as well :) First of all, I would like to thank HELIS for giving me this opportunity. I remember when the news about this certification came out, our Laravel team decided to go for it and we spent a month or two preparing for it. Each weak we would gather in a meeting room for some presentations on chosen topics. One or two teammates would prepare some slides with sample code and we would discuss it after presentation. We even took our own created exams :) However, even though vouchers have been ordered, it took quite some time to get emails telling that we can now take the exam. This certification is still new and was only in beta at first, but now they are rolling out emails to everybody. They still don't have yellow pages with a list of certified developers, but are working on that. I was interested on what will be the process of certifica...