Eneba developer blogEneba developer blog
http://engineering.eneba.com/
Sat, 17 May 25 15:22:00 +0000Fri, 18 Jul 25 02:01:07 +0000en-UShttps://static.eneba.games/favicon.icoEneba
http://engineering.eneba.com/
6464Symfony setter injection
The Symfony documentation
explains four ways to inject dependencies to your service. In short, you can use
the constructor, inject directly to a public property or you can use a two flavours
of injection via a method.
Short example:
# config/services.yaml
services:
App\Service\MyFancyService:
calls:
- setLogger: ['@logger']
class MyFancyService
{
private LoggerInterface|null $logger = null;
public function setLogger(LoggerInterface $logger): void
{
$...
Sat, 17 May 25 15:22:00 +0000
http://engineering.eneba.com/blog/symfony-setter-injection.html
http://engineering.eneba.com/blog/symfony-setter-injection.htmlPerformance test: Bref FPM vs Bref + Runtime component
The Symfony Runtime component is AWESOME. I did a talk about it at
Symfony World 2021 where I explain how and
why it works. I spent a lot of time on the content and the recording, one can still
watch the replay.
Since that talk, I've been deploying a few applications on Bref
using runtime/bref. I really like building
and deploying applications this way.
I did a small test if there is any performance difference between using Bref's FPM
layer compared to using Bref with the runtime component. I te...
Mon, 06 Sep 21 06:44:00 +0000
http://engineering.eneba.com/blog/performance-test-bref-runtime-component.html
http://engineering.eneba.com/blog/performance-test-bref-runtime-component.htmlSymfony Lock and Messenger component
The lock component have saved me so many times. It helps me with race conditions,
it makes my code simpler and my application more reliable. I'm using it to fix all
kinds of problems and I've noticed that I use a few different methods. This article will
try to explain these methods or "strategies". My hope is to make life simpler for everybody else to
implement Symfony Lock component with Messenger.
No two messages handled at the same time
This strategy is the simplest one and is good ...
Sun, 14 Feb 21 11:51:00 +0000
http://engineering.eneba.com/blog/symfony-lock-and-messenger-component.html
http://engineering.eneba.com/blog/symfony-lock-and-messenger-component.htmlOne year of AsyncAws
It has been one year since Jérémy Derussé and I started to work on a new API client
for AWS. At the time we could never have imagined how popular it would be. In this
first year we had over 1.5 million downloads over all packages. The core package
alone has been downloaded more than 500.000 times.
The story behind the project is simple. We wanted an AWS client that was fundamentally
different from the official one. The big features are all described on async-aws.com,
but in short: we use small p...
Sat, 09 Jan 21 11:18:00 +0000
http://engineering.eneba.com/blog/one-year-async-aws.html
http://engineering.eneba.com/blog/one-year-async-aws.htmlFinding the correct values for Symfony Messenger failure strategy
Symfony Messenger is great. It has so many features and is super flexible. I want to
highlight one of these features in this small post: Failures and retries.
Over in the Symfony docs
failures and retries are briefly mentioned and it explains what values you can configure.
However, it does not give a good recommendation for what values to use. The simple
answer to "What values should I use?" is "It depends".
Depending on what your application requirements are these values wil...
Mon, 04 May 20 10:44:00 +0000
http://engineering.eneba.com/blog/finding-messenger-failture-strategy.html
http://engineering.eneba.com/blog/finding-messenger-failture-strategy.htmlInstalling Blackfire on multiple servers
We have a lot of applications running on both EC2 machines and
a lot of Lambda functions. Most of them are small microservice applications that
are rarely updated with new features. We've installed and configured the
applications so we can run Blackfire's profiler on each of these applications.
Blackfire's internal architecture allows us to install the profiler in a
clever way, compared to other profilers I've tried.
This article will go over how to install Blackfire when you have multiple serve...
Sun, 26 Jan 20 16:21:00 +0000
http://engineering.eneba.com/blog/installing-blackfire-multiple-servers.html
http://engineering.eneba.com/blog/installing-blackfire-multiple-servers.htmlPHP 7.4 preloading benchmark
Preloading arrived to PHP 7.4.0 in November 2019. I was super excited about this
and I started to try it out. But I quickly noticed that it was a little buggy when
you started with a "real world" application. It worked fine for small hello world
apps.
One example of such issues are with class_alias, which is a common practice to
use by libraries that want to provide backwards or forwards compatibility. If you
were trying to preload a file like that, then PHP-FPM failed to start with ou...
Sat, 18 Jan 20 09:43:00 +0000
http://engineering.eneba.com/blog/php-74-preload.html
http://engineering.eneba.com/blog/php-74-preload.htmlOptimize images on S3 with AWS Lambda and Serverless
An image is uploaded on S3, that triggers a lambda that optimize that image and put it back. How hard can that be?
It was way more tricky than I thought, especially since Im not used to the Node ecosystem. So here I am sharing my
research and result. I hope it can be useful.
Requirements
I wanted to use javascript because there is native support for Node on AWS Lambda. I am also under the impression that
there are tonnes of great node libraries that help me optimize images. Node8 is soon to be d...
Sun, 29 Dec 19 21:40:47 +0000
http://engineering.eneba.com/blog/aws-lambda-image-optimization-with-serverless.html
http://engineering.eneba.com/blog/aws-lambda-image-optimization-with-serverless.htmlSymfony HTTP Client and caching
Symfony has a HTTP client which differ from other clients
like Guzzle, Buzz or clients from the HTTPlug organization. Symfony's HTTP client is asynchronous by default. Using
asynchronous anything is strange in PHP but there is no magic. The asynchronous part in any PHP HTTP client is achieved
with help from cURL.
Asynchronous by default means that we are only making the HTTP request when we actually need data from the response. This
allow us to start multiple requests and let cURL execute them i...
Thu, 12 Sep 19 14:35:00 +0000
http://engineering.eneba.com/blog/http-client-and-caching.html
http://engineering.eneba.com/blog/http-client-and-caching.htmlSymfony Messenger on AWS Lambda
For the past 4 years we have developed web applications with a message bus. The Symfony Messenger component was released
around a year ago and I've loved it since. In the past few weeks we've been deploying applications on AWS Lambda. Going
serverless is super cool since you can scale up and down, it is cheap bla bla bla. The major selling point to me is that
you don't need to care about dev ops once it all up and running. We've been using Bref and I can highly
recommend it.
When running your ap...
Mon, 24 Jun 19 09:13:00 +0000
http://engineering.eneba.com/blog/symfony-messenger-on-aws-lambda.html
http://engineering.eneba.com/blog/symfony-messenger-on-aws-lambda.htmlUsing NewRelic with Bref on AWS Lambda
Running serverless is great. When migrating our applications to use Bref we realized that we need a non-standard php-extension.
With "non-standard" I mean that the extension is not included by default by Bref. With some help I manage to make every
thing work as I wanted it to. Here is what I did:
I cloned the Bref repository to be able to build my own image. Then I added the NewRelic extension and config to php.Dockerfile
in the /runtime/php directory.
## Install NewRelic
RUN \
curl...
Fri, 21 Jun 19 18:18:47 +0000
http://engineering.eneba.com/blog/newrelic-on-bref-aws-lambda.html
http://engineering.eneba.com/blog/newrelic-on-bref-aws-lambda.htmlBlocking vs non-blocking fonts
Just the other day I found out about the font-display: swap;
css directive. It basically allows you to configure the browser to load the webpage
first and then add the correct fonts when they are loaded.
Note that you can only add font-display: swap; on @font-face. That is an issue
because we are using Google fonts. So I downloaded the CSS file from Google fonts
and stored it locally. Then I added font-display: swap; on all @font-face like:
@font-face {
font-family: 'Roboto';
font-style: no...
Wed, 20 Mar 19 10:38:47 +0000
http://engineering.eneba.com/blog/blocking-vs-non-blocking-fonts.html
http://engineering.eneba.com/blog/blocking-vs-non-blocking-fonts.htmlSymfony State Machines and Domain Driven Design
It has been just over 2 years since Symfony released their Workflow component.
I was of course thrilled by the news and started to work on multiple PRs to make
the component support state machines. It was a really cool experience working with
the Symfony community and discussing everything from Petri nets to minor code
optimizations.
I often get questions how to work with the Workflow component and questions like
"what should I do in this really specific scenario". One question I do ge...
Mon, 25 Feb 19 22:23:47 +0000
http://engineering.eneba.com/blog/symfony-state-machines-and-domain-driven-design.html
http://engineering.eneba.com/blog/symfony-state-machines-and-domain-driven-design.htmlDefine Symfony access control rules in a database
I was recently at a PHP conference in Odessa where I met many great developers.
One of them asked me a question, that the answer was not obvious. His use case
was that he wanted to use Symfonys Access Control configuration to restrict access
in his application. But he also wanted to configure the rules dynamically.
Since all the configuration in Symfony is cached with the container for performance
reasons, we could obviously not allow a use a database to somehow "print" new configurati...
Sun, 12 Aug 18 22:23:47 +0000
http://engineering.eneba.com/blog/define-access-control-in-database.html
http://engineering.eneba.com/blog/define-access-control-in-database.htmlTesting the Symfony 4.1 router
How much faster is the new Symfony router in a real world application?
We ran some tests to find out.
An improved router
A few days ago we received the fantastic news that the Symfony router had been improved significantly. Of course we wanted to see how
the changes would affect our application, so we decided to test it against our own routes.
If you somehow missed the news you can read the official announcement.
If you want to know how the new router works, read Nicolas Grekas post where he div...
Fri, 02 Feb 18 15:06:47 +0000
http://engineering.eneba.com/blog/symfony-route-test.html
http://engineering.eneba.com/blog/symfony-route-test.htmlGenerate URLs in Symfony commands
It has been great many years since Symfony 2.0 was released. 2.0 did not have as many great features as Symfony 4.0, but
it was flexible and you could still accomplish what ever you want. I've just found out one small thing that Symfony 4.0
does way better that 2.0.
EDIT: This is not new to Symfony 4.0. It was a feature already in 2.7.
Long long time ago I had the need for creating a Symfony command that sends emails to users given some criteria. So I wrote
my command and set up my cron job and ...
Wed, 31 Jan 18 08:23:47 +0000
http://engineering.eneba.com/blog/generate-url-in-symfony-commands.html
http://engineering.eneba.com/blog/generate-url-in-symfony-commands.htmlAlways use caret instead of tilde
I've been noticing people having trouble understanding the differences between the caret ("^") and the tilde ("~") operator
in the composer.json file. Composer's documentation is great but a bit short, that is why I write this blog post.
Composer assumes that all packages are using Semver. It is an easy version schema that consists of a major.minor.patch version. A major version breaks backwards compatibility, minor version introduces new features and patch versions are bug f...
Fri, 05 Aug 16 08:23:47 +0000
http://engineering.eneba.com/blog/always-use-caret-instead-of-tilde.html
http://engineering.eneba.com/blog/always-use-caret-instead-of-tilde.htmlOpen files in PHPStorm from you Symfony application
If you want to open files in PHPStorm8 directly from the Symfony debug toolbar there
is a neat trick you can use. This is very helpful when you quickly want to find
a controller or when you got an exception.
// /config/packages/framework.yml
framework:
ide: "phpstorm://open?file=%%f&line=%%l"
You could also do this trick locally on your machine instead. That will not conflict
with other developers in your team and it will work for all your projects.
; php.ini
xdebug.file_link_f...
Wed, 15 Apr 15 08:55:00 +0000
http://engineering.eneba.com/blog/open-files-in-phpstorm-from-you-symfony-application.html
http://engineering.eneba.com/blog/open-files-in-phpstorm-from-you-symfony-application.htmlChoose owning side in OneToOne relation
Many times I've come got to a situation where I have a unusual high query count. When I inspect the queries in the Symfony profiler I can see that Doctrine is fetching objects I have not requested. To give you a clear image of the problem I'll show an example of the database mapping.
class User {
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\OneToOne(targetEntity="Res...
Thu, 26 Jun 14 12:16:41 +0000
http://engineering.eneba.com/blog/choose-owning-side-in-onetoone-relation.html
http://engineering.eneba.com/blog/choose-owning-side-in-onetoone-relation.html