Let's take a quick look at how best to set up PHP-FPM for high throughput, low latency, and more stable CPU and memory use. By default, most setups have PHP-FPM's PM (process manager) string set to dynamic and there's also the common advice to use ondemand if you suffer from available memory issues. Continue reading...
#php
72 posts
6 Jun
3 Mar
Recently I discovered that this code passed our PHPStan level 10 checks: use http\Exception\InvalidArgumentException; // ... throw new InvalidArgumentException; I was surprised as http\Exception\InvalidArgumentException is not a class in our system. While cooling, I discovered that there's an http PHP extension and it appears that PHPStan has a stub for this which means that it accepts it as existing even…
6 May 2025
On the Roave Discord recently, there was a discussion about not breaking BC in interfaces inspired by this post by Jérôme Tamarelle: It's clearly true that if you add a new parameter to a method on an interface, then that's a BC break as every concrete implementation of the interface needs to change their signature. However, Gina commented that you…
25 Feb 2025
One of the bigger changes in PHPUnit 10 was the introduction of the new extension system which replaced listeners and hooks. The old way On one of my projects we have a TestListener that sets up the database before we run some functional tests against it. It looks like this: <?php declare(strict_types=1); namespace App\Test\Listeners; use App\Test\Functional\Helpers\DbHelper; use PHPUnit\Framework\TestListenerDefaultImplementation; use PHPUnit\Framework\TestSuite;…
24 Sept 2024
When Guzzle throws BadResponseException, the message includes information about the method, URL response code and then a truncated part of the body. For example: "Client error: `GET https://dev.clientproject.com:4444/oauth2/authorize?client_id=983e98d2fab8756a&scope=scope&response_type=code&redirect_uri=%2Fhome&code_challenge=some_code_challenge_here` resulted in a `400 Bad Request` response: {"error":"invalid_request","error_description":"The request is missing a required parameter, includes an
17 Sept 2024
Recently, I set up my PHP dev environment to allow me to step debug from unit tests that I run with make unit The relevant parts of Makefile look like this: # Set DEBUG=1 to enable Xdebug ifeq ($(origin DEBUG),undefined) XDEBUG := else XDEBUG := XDEBUG_SESSION=PHPSTORM endif unit: ## Run unit tests docker compose exec php bash -c "$(XDEBUG) vendor/bin/phpunit…
10 Sept 2024
I'm working on a project that uses MS SQL Server as its database. Recently, I noticed that the SQL Server Docker container now works with Apple Silicon Macs, so looked into setting up a PHP-FPM container with the sqlsrv extension installed. I'm noting the relevant parts of my Dockerfile for when I need them again, so this is entirely an…
3 Sept 2024
For one project that I'm working on the PHP-FPM-based Docker container is built from a Ubuntu container with PHP is installed into it. A little like this: FROM ubuntu:22.04 RUN apt-get update && apt-get upgrade -y && apt-get install -y gnupg curl # Register the Ondrej package repo for PHP RUN mkdir -p /etc/apt/keyrings \ curl -sS 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x14aa40ec0831756756d7f66c4f4ea0aae5267a6c' | gpg…
25 Jun 2024
When I write integration tests with PHPUnit, I find it helpful use Monolog's TestHandler to check that the logs I expect are generated. It's reasonably common that classes that write to a log take a PSR\Log\LoggerInterface in their constructor and then use that for logging. This usually logs to the error handler for pushing to Sentry or whatnot. This makes…
9 Apr 2024
With some commercial projects, it can be useful to know that all your dependencies have licences that your organisation deems acceptable. I had this requirement for a few clients now and came up with this script that we ran as part of our CI which would then fail if a dependency used a license that wasn't allowed. This proved to…
26 Mar 2024
In order to verify a JWT created with an asymmetric key, the verifier needs to get the correct public key. One way to do is described in RFC7517 which describes the JSON Web Key format. Within the header of the JWT there is a kid property which is the key ID which is then used to find the correct key…
19 Mar 2024
The most common use of JWTs is as an authentication token, usually within an OAuth2 workflow. Creating these tokens is part and parcel of the authentication library that you use. I recently had a requirement to use a JWT independent of authentication and these are some notes on what I learned when researching with Lcobucci\JWT. Make up of a JWT…
21 Jun 2023
In this post, I will explain the steps to deploy a simple PHP email MX record validation application on AWS lambda function using Bref layers. AWS Lambda natively supports Java, Go, PowerShell, Node. js, C#, Python, and Ruby code, not PHP. You can deploy the lite weight PHP function to improve the application performance and it will reduce cost compared…
21 Feb 2023
I have just returned from the 2023 edition of PHPUK and, as always, found it a valuable conference to catch up with the PHP community and find out what’s happening in the ecosystem. This year, I was accepted to speak on the differences between RPC, REST and GraphQL APIs and was surprised and gratified that the room was at full…
15 Oct 2021
Nowadays most of my side projects are managed with Github. It has more advantages and flexibility to manage file versions. I am following a different webhook system to automatically deploy my old PHP projects. Not sure about the standards, but the following solution is an alternative approach that may solve your deployment problem for every Github push.
8 Aug 2021
Few days back one of my friend's project database credentials got exposed. After some investigation, we realized that it is because of the .git config commit. I would recommend configuring your sensitive credentials with operating system environment variables. This way you can protect information from the code base. This post will explain how to set up an environment variable for…
7 Aug 2019
Microsoft Azure is another great alternate cloud service and it is offering a one-year free trial with $200 credit. This post is almost similar to my previous Cloud service article. This will explain to you how to set up a virtual machine instance with secure firewall rules and setting up a XAMPP(PHP Maria DB Server) using the Ubuntu operating system.…
30 Jul 2019
Google cloud platform is a cloud computing service and a perfect alternate for Amazon Webservices. Nowadays most of the top companies are moving towards Google services for better results. Google cloud platform is offering a $300 free trial for one year. This post is about how to set up VM instances with firewall rules in addition to creating a XAMPP…
18 Dec 2018
In a previous post, Docker PHP/PHP-FPM Configuration via Environment Variables, I described how to use environment variables to configure PHP FPM and CLI. With my method you can override one of over 650 PHP INI settings. More INI settings are but a PR away! In a more recent post, PHP Modules Toggled via Environment Variables I extended this concept to…
14 Dec 2018
In my previous post, Docker PHP/PHP-FPM Configuration via Environment Variables I introduced my new PHP image that uses environment variables to configure its INI settings. The Dockerfile is a beast, to be sure. At over 650 lines it documents my attempt at bringing true flexibility to an immutable PHP image. With it, you can set any number of PHP INI…
15 Nov 2018
ed: If you want to run the containers right now, jump ahead to How to Use the Images. For several months now I have been working on PuPHPet.com’s replacement. It is a Docker-based GUI functionally similar to PuPHPet. Docker, like Vagrant, allows sharing directories and files from the host to the container/VM. Unlike Vagrant, Docker images are easy to create,…
23 Jul 2018
A quick history ed: If you want to jump right to the solution, jump ahead to Nginx map. Docker for Mac is very slow. It is so slow that I purchased a new Dell XPS laptop and for the first time in 6 years am now using a non-MacOS (Fedora) machine as my daily driver. Not everyone has the luxury…
7 May 2018
Laravel is a PHP framework that uses Eloquent, a powerful and amazing ORM that allows you to do complex SQL queries in a very easy way. But sometimes you need more, and here I’m gonna give you an interesting tip that can bring you a lot of flexibility. When dealing with simple database queries in … Continue reading Querying and…
30 Apr 2018
Testing with Laravel is very easy, but it can be a nightmare when the tests depend on Events and Listeners. In this post I’m gonna show you how you can simplify and improve those tests. Laravel is one of the most popular PHP frameworks nowadays, and I’d say its Event handler is one of the … Continue reading Solitary or…
23 Apr 2018
Having a clean code with single responsibility is important, and doing that for model filtering can be easy and very powerful. Believe me. This blog post is related to a talk I gave on April, 2018 on Darkmira Tour PHP 2018, in Brasília/DF, Brazil, with the same title. The slides are on SpeakerDeck. Filtering models … Continue reading QueryFilter: A…
26 Mar 2018
Maintaining an open source project – even a small one – is not an easy task. The open source ecosystem is about sharing and contributing, about giving and receiving. You scratch my back and I will scratch yours. Open-source is not only a free and open software, it’s a lifestyle. Working with open-source is working … Continue reading Open-source is…
12 Mar 2018
Learn how to use a very simple and efficient service called ServerPilot for provisioning a web server to host your next PHP project or blog. Provisioning a well-configured web server for a PHP application is not an easy task. You can have experience doing that, but this is not my strongest skill, I admit. So … Continue reading Easy server…
5 Mar 2018
Being really good in your field is important, but more important than that is to seem to be good. Invest in yourself. Be searchable! How many times did you search your name on Google? How many times did you search some keywords related to you? Did you like the results you got? Can them be … Continue reading Invest in…
26 Feb 2018
Open source can change your life. It has changed mine with Corcel, an open source project I started in 2013 that changed who I am, and how I live. The first title I gave to this post was How open source can change your life for the better. That was a good title too, but I … Continue reading Why…
16 Feb 2018
Learn how to configure XDebug and PHPUnit in PHPStorm, allowing you to write better tests and fix bugs faster. Test Driven Development (TDD) is an old topic, I know, but it seems many people don’t understand how it makes you write better code. The point here is that one of the most important benefits it’s … Continue reading Using XDebug…
23 Mar 2016
This post shares 6 tips to build fast web applications based on a talk at Php Dublin in March 2016. It includes slides and covers topics like caching, compression, database optimization, and more.
25 Jul 2015
This post highlights 6 important rules to keep in mind when developing performant web applications: avoid premature optimization, do the minimum required work, defer non-critical tasks, leverage caching, avoid N+1 queries, and design for horizontal scaling. Following these guidelines will help you write efficient code from the start and build apps ready to handle growth.
24 Jul 2015
For two weeks I have been heavily developing a new web application based upon Laravel. Tonight I searched for an easy filtering solution like Zend_Filter so that the request strings are automagically trim’d, lowercased, and so on. Lucky me, the repository https://github.com/rmasters/filter is available with a composer.json but latest commit […] The post Using GitHub forks or local Git repositories…
18 Apr 2015
This tutorial shows step-by-step how to bootstrap a Lumen project, configure MySQL, create migrations and models, seed the database, define routes and templates to build a fully working motivational quote web app in less than 30 minutes.
27 Feb 2015
Hello!!! Every project you have to make some requests using Ajax, right? I know that jQuery has done a very good job and almost all project you start it is present there, together with your Javascript files. So you can make Ajax calls any time, where you want, just making the call using Javascript. I … Continue reading Using Ruby…
21 Feb 2015
The Symfony HttpKernel Component allows interacting with the response generation through events. The Kernel Response event permits modifying the response before sending it out. Two examples show how to use it to add custom headers and cookies without touching controller logic.
13 Jan 2015
Hi everybody! Here I’m again to write my first post in 2015. Last year I’ve wrote less and this year I have plans to write much more, telling about my experience with web development. I have plans to start screencasting too, but this is just plans 😀 I decided to start this year writing about … Continue reading Why WordPress…
13 Jun 2014
This blog post explains how to implement email open tracking in Symfony using a transparent tracking pixel. It provides code examples for generating a tracking image response and handling the tracking logic in a controller.
26 Apr 2014
Hi everybody! Updated Mar 3rd 2015: Are you using Laravel 5? Check these changes! Updated May 11th 2014: Using Corcel project Currently I am working on a project where I had to make some choices about technologies and how work with them together. First this project will be developed using WordPress only. It’s a College … Continue reading Working with…
11 Apr 2014
ORM Cheatsheet is a useful website that serves as a quick reference guide for developers struggling to remember how to use common PHP ORM libraries like Doctrine 2 and Propel. It provides examples for annotations, relationships, and configuration.
15 Mar 2014
This article shows how to build a simple command line application using the Symfony Console component and Pimple dependency injection container. It provides a step-by-step guide on structuring the code, defining services, configuring parameters and wiring everything together to create a executable console app.
28 Feb 2014
The post explains how to integrate twig.js with BazingaJsTranslationBundle to handle translations consistently between PHP and JavaScript. It shows how to build a custom Twig extension to translate strings with the Bazinga Translator object and handle differences in parameter formatting.
14 Feb 2014
This post collects resources and provides a graph to understand how Symfony authentication works behind the scenes, from the initial request to the final authenticated token. It clarifies the relationships between key classes like firewall, authentication provider and authentication listener.
10 Feb 2014
This post explains how to add support for Instagram to the PHPoAuthUserData library by writing a dedicated extractor class. It illustrates the concepts of loaders, normalizers and mapping to extract user profile data from the Instagram API.
The PHPoAuthUserData library provides a simple interface to extract common user data like name, username, ID from various OAuth providers. It builds on top of PHPoAuthLib.
6 Nov 2013
Let’s supose you want to develop your own URL shortener, like Bit.ly for example. You can, of course, use the ID as a integer, like, 1, 2, 3, etc. If you have 12.345 rows in your database table, you will need 5 digits, like http://example.com/12345. Large applications like Youtube, have much more entries, so, to … Continue reading Generating IDs…
4 Nov 2013
Generally assets are stored in your public directory, right? They are public, so anyone can get access to them. But nowadays the performance is a very important factor when deploying a new app. I strongly recommend you to minify and cache your assets, like CSS files, Javascript files and Images. If you are using 11 … Continue reading Managing assets…
14 Oct 2013
One of the best improvements of the PHP 5.4 was the built-in web server. Like in Ruby On Rails, now you do not need Apache or Nginx inside your development machine. To start a web server is easy: php -S localhost:8000 Remember you can choose the port you want. You can use localhost:8000 or localhost:8080 … Continue reading Working with…
25 Sept 2013
Actually this post is a outflow and at the same time an advice. I have seen some PHP developers that are completely OUT of what is happening in the PHP world, besides committing some mistakes that cannot be accepted. PHP 5.3+ If you are entitled as a PHP developer you must to update. In my … Continue reading Be a…
18 Sept 2013
These days I’m thinking about productivity and the use of PHP frameworks. I’ve read some posts about framework X or Y, defending a framework instead of another one. I know people that use a framework like Zend Framework to develop a simple website just to say they’re using it, and not an “easy” framework. I … Continue reading Solve the…
24 Jun 2013
Hi all! Today I am starting a post series about Design Patterns. I have wrote about them a lot but only suggesting you to learn about to be a better developer. I am studying them, so nothing better to write about and improve my knowledges too. I only ask you to read everything to understand … Continue reading Design Patterns…
21 Jun 2013
Hello again! It’s my second post today! I’m electric! I am developing a project that uses a package I’m developing too. So, it is a real time test project. I find a new way to do something and write it inside my package and uses that. But sometimes this is a boring work. I am … Continue reading Testing your…
Hi guys! Everyone wants to contribute in some way with developers. Maybe you’re thinking in a project to develop and share but you search at Google and find someone who already did that. Maybe the answer to this problem is in front of you. Everything you do can be reused in a future project. If … Continue reading Contributing with…
7 Mar 2013
Hi everybody! Today I’ll write about how you can contribute with PHP community creating packages (or updating your’s) using Composer and Packagist. First, if you’re a PHP developer and don’t know yet what is Composer, take a look on the post Why you should use Composer and how to start using it to get more … Continue reading Creating your…
26 Jan 2013
Hello! One of the most big changes happening in PHP world is the Composer. I’m shure you heard about it but maybe you don’t know why you should use it and how much it is good for you and your projects. What is Composer? When you need some specific code in PHP you can go … Continue reading Why you…
25 Jan 2013
Hello! Today I had to update a project that was developed using WordPress and PHP 5.3. Today I have PHP 5.4 installed on my machine and this newer version abandoned some old features, and you have some Fatal errors like Call-time pass-by-reference has been removed. The solution was go back to PHP 5.3 and do … Continue reading Working with…
22 Jan 2013
Hello everyone! Use or not to use a PHP Framework on your new projects? Here I’ll talk about my personal opinion about that and I wish help you. First, I have a simple concept about languages and respectives frameworks: a framework must make the development simpler. Every software has a single purpose: work! This is … Continue reading Why you…
11 Oct 2012
Hello! Laravel is an awesome PHP framework created by Taylor Otwell. Actually, it is on the third version and it is one of the great PHP frameworks we have today. As a lot of frameworks, we have to create our own Apache Virtual Host to point to the public dir to improve security and only … Continue reading Deploying Laravel…
19 Sept 2012
Hello all! Let’s continue with our WordPress series. Today I’ll write about the main files in a WordPress theme. First files Above we have some files that are basic for your new theme: index.php This file is the root file, the home page. When you open your WordPress website it’ll get this file content. Is … Continue reading Creating your…
15 Sept 2012
Hello everyone! As I said, this is our second post about Themes in WordPress. Today I’ll talk about: How to create page templates How to retrieve posts If you want you can read the first post about WordPress themes. Let’s GO! Page Templates You can customize pages the way you want, as you want. If … Continue reading Creating your…
13 Sept 2012
Hello again… Continuing with our first WordPress site, now we’ll understand how WordPress allow you to customize themes. If you didn’t read the first post about WordPress Thinking the WordPress Way – First Steps and want to learn how WordPress works, take a look. You don’t have to change your layout or using specific techniques … Continue reading Creating your…
Hello everybody! I work with PHP since 8 years and I never took a look on WordPress. In the start of this year a customer requires me to develop his next website, but using the WordPress. So I had to search some tutorials on the Internet and join informations to make my own way to … Continue reading Thinking the…
13 Dec 2011
Hello. Another quick tip. To start a new Zend Framework project, the easiest way is using Zend_Tool for that. Please, install first the Zend_Tool follow this link at Zend Framework documentation page. Creating new project Let’s starting using the command line and creating a new ZF project. zf create project my_project_name Zend_Layout Now, get in … Continue reading Creating new…
Hi all. Here I am again. Today I have a quick tip for beginners using Zend Framework. Do not insert pre and post code (for database) in your Controller. The Zend_Db_Table_Row is for that. Lets create our DatabaseTable class for Posts: /** * Located in .../models/DbTable/Posts.php */ class Posts extends Zend\_Db\_Table_Abstract { protected $_primary = … Continue reading Pre and…
20 Jul 2011
Hello everybody! Usually I have direct access (shell) in all the servers that host my Zend Framework applications, but, some clients already have a shared host, so I have to deploy the application there too. I was thinking how can I never thought this before! There are a lot of ways to deploy a Zend … Continue reading Deploying Zend…
15 Jul 2011
Hi every one! I just read a small but very interesting post in BrownPHP website with a comparison between Zend Framework and CakePHP Framework. The post is below and the original article is here. The Zend Framework, developed by Zend Technologies is an open-source, object oriented web-application framework implemented in PHP 5. It is widely … Continue reading Zend Framework…
13 Jul 2011
Hi everyone, Here I am again. Yesterday a friend asked me how to create the basics CRUD (Create, Release, Update, Delete) operations using Zend Framework. As everybody now, a basic CRUD it’s a good way to understand some framework’s resources to a new ZF developer. As he is a newbie with Zend Framework, the example … Continue reading Basic CRUD…
11 Jul 2011
Hi all… Here we are, again. This will be a quick post, just for warning in a specific case. When you’re using the jQuery Form plugin by malsup.com you are making an AJAX call, but it does not send some variables that identify a XMLHttpRequest (in my case I’m using the plugin with a upload … Continue reading jQuery Form…
21 Jun 2011
Boa tarde, pessoal! É muito comum em aplicações web a necessidade de trabalhar com imagens, tanto para redimensionamento, criação de thumbnails, girar, etc. Apresento a Asido, um conjunto de classes para trabalhar com imagens em PHP. Embora eu não goste muito da forma de organização de OO que a Asido utiliza, é uma boa ferramenta … Continue reading Redimensionamento, rotação…
Olá pessoal! Esta semana estou trabalhando num projeto onde a utilização de Ajax está sendo muito útil em termos de performance e facilidade na busca de produtos no banco de dados. Como estou utilizando Zend Framework no projeto, vou explicar resumidamente como trabalhar com requisições Ajax no ZF. Basicamente, o óbvio seria desabilitar a renderização … Continue reading Utilizando AjaxContext…
16 Jun 2011
Olá pessoal. Indo direto ao assunto, sempre tive dúvidas quanto a usar o Poedit para traduzir strings, motivo pelo qual usava mais arrays em PHP mesmo. Porém, mais cedo ou mais tarde, necessitamos evoluir e correr atrás do tempo perdido. Sempre achei o Poedit chato e nunca conseguia fazê-lo funcionar. Após umas fuçadas na net … Continue reading Tradução usando…
31 Mar 2011
As I mentioned yesterday, Christoph is currently developing the Active Directory Integration WordPress plugin. Today we were talking about the write back of WordPress profile settings to Active Directory. I mentioned it would be helpful to have an abstract definition of available Active Directory attributes which can be dynamically integrated […] The post Convert Active Directory schema to XML or…