Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Using php-fpm as a simple built-in async queue
Aug 21, 2017 @ 09:25:20

On the Tideways blog Benjamin Eberlei has written up a post showing how to use php-fpm as a "poor man's queue" system, making it easier to hand off requests to be worked on out of band without having to install other software.

There are many tasks that a web-request should not perform directly so the user doesn't have to wait many seconds for a response. [...] The usual advice you find on the internet is to setup a queue such as RabbitMQ, Redis, Kafka, Gearman or Beanstalkd. But this means another service that you need to install, setup, maintain and monitor. With some of the queue systems operating them includes a steep learning phase that requires time and money for additional hardware.

But maybe you just need a poor mans version of an asynchronous queue without all the overhead? Then why not just use PHP-FPM itself?

He admits that it's more of an "experimental approach" but feels like it could be a viable option for the php-fpm users out there. He then shows how to use the hollodotme/fast-cgi-client library to execute an asynchronous request for a "SendEmail" command. The request is then passed off to another PHP-FPM worker for processing without the user having to wait on a result. He ends the post with a few words of warning about using this approach and some other methods for getting around the offloading of longer processing.

tagged: phpfpm asyncronous library tutorial offload processing socket

Link: https://tideways.io/profiler/blog/using-php-fpm-as-a-simple-built-in-async-queue

Marc Schmidt:
PHP High-Performance - Follow Up with Symfony/Jarves.io and PHP-PM
May 02, 2016 @ 12:08:37

In a follow up to his previous article about high performance PHP with React's help, Marc Schmidt has returned with a follow up post two years after the fact with some updates and additional information.

This is a follow up article on “Bring High Performance Into Your PHP App”, which went quiet viral with over 100k visits. This does not only show that many people still struggle with PHP and its performance, but also that people are highly interested in a solution to this kind of issues. PHP-PM could be one solution. But first things first. Over two years later since my blog post about high-performance things have changed dramatically.

[...] When I hacked together some lines of code back then in 2013 I never though that this kind of application style would ever succeed in the PHP world. [...] However, things have changed there as well.

He talks about some of the advancements that have been made since his previous post including PHP 7, improvements in PHP-FM and the HttpKernel component of the Symfony framework. Along the lines of bringing even more performance to PHP applications with React, they created an adapter to link the two. The post covers some of the currently open issues, the "good things" about it and some of the design issues to keep in mind when using it. He ends the post talking about where the PHP-PM project is now and some of the benchmarks about performance between PHP-PM and PHP-FPM.

tagged: performance react httpkernel phppm phpfpm adapter benchmark

Link: http://marcjschmidt.de/blog/2016/04/16/php-high-performance-reactphp-jarves-symfony-follow-up.html

Loïc Faugeron:
Super Speed Symfony - nginx
Apr 20, 2016 @ 10:48:49

Loïc Faugeron has continued his series about speeding up Symfony applications and getting the best overall performance you can. In this new post he gets into more detail about tuning a Nginx web server (with PHP-FPM) and the web server's own caching features.

HTTP frameworks, such as Symfony, allow us to build applications that have the potential to achieve Super Speed.

We've already seen a first way to do so (by turning it into a HTTP server), another way would be to put a reverse proxy in front of it. In this article we'll take a Symfony application and demonstrate how to do so using nginx.

He starts by helping you get Nginx and PHP-FPM all set up and running on a Unix-based system (installed via apt-get). He provides a simple configuration including the user to run as and a virtual host for the application. There's a few command line checks to ensure it's working correctly and a bit of benchmarking as a baseline for the performance testing later. He then gets to the caching functionality and gives some of the basics on how it works inside of Nginx itself. He includes a basic caching configuration (caching to files) and adding this to the already created virtual host. Finally he includes sample Symfony code to send the "Cache-Control" header with every request and runs the benchmarks again (resulting in about 140x faster than without the cache).

tagged: tutorial nginx performance symfony speed phpfpm setup configuration cache cachecontrol

Link: https://gnugat.github.io/2016/04/20/super-speed-sf-nginx.html

Vincent Composieux:
Run a Symfony application using Docker and docker-compose (English)
Apr 30, 2015 @ 10:53:48

Vincent Composieux has put together a new tutorial showing you how to get a Symfony2 application up and running inside of a Docker virtual machine for development and testing.

Why boot a full virtual machine when you can only run Docker containers of what you need to develop your Symfony applications ? This is one question asked by Jeremy Derusse at his "Docker dans le développement l'intégration continue" talk during Symfony Live Paris 2015. Those slides are really interesting, I invite you to take a look. They demonstrate the power of Docker and docker-compose but are waiting for practice in order to well understand. So I enjoyed a rainy week-end for further study!

He then outlines the components needed for a simple Symfony2 application: Nginx, PHP (well, PHP-FPM), MySQL and, of course, the code for the application. He includes the full contents for the "docker-compose.yml" configuration file to generate this Docker instance. He walks through each of the components it requires and talks about what they contain and how to define each of them as an image. Following this, he creates the containers with a "docker build" and brings it all up and working with one "docker up" command. He also includes a few other helpful commands for getting memory/CPU usage as well as removing all containers and images with a single command.

tagged: symfony2 application docker tutorial dockercompose nginx mysql phpfpm

Link: http://vincent.composieux.fr/article/run-a-symfony-application-using-docker-and-docker-compose

Get a Handle on PHP Handlers
Mar 25, 2015 @ 10:25:47

On DZone.com today there's a post covering the different kinds of handlers that can execute PHP - those pieces of code that work with the web servers we use every day to interpret and execute PHP code.

PHP Handlers? mod_php? FPM? How do we make sense of the inner workings of PHP outside of our lines of code? We know we can run PHP on the server to build web applications swiftly, but how can we optimize our environment and configurations to reach maximum scale? We know that PHP has its drawbacks for not being asynchronous or event-driven, which is all the more reason to ensure maximum optimization. The impact of your server environment on your PHP application performance can be more than you think you can afford. A careful examination of your PHP ecosystem will help you avoid suffering performance loss in areas you can otherwise solve for easily.

They provide a brief summary of what PHP handers, well, handle and where they fit in the overall architecture of execution. They then get into the details on some of them:

  • CGI – mod_cgi
  • suPHP – mod_suphp
  • DSO – mod_php
  • FastCGI – mod_fcgid
  • FPM (FastCGI Process Manager) – php-fpm

Included in each is an overview of how it works and some of the main advantages (and disadvantages) of their use. He also mentions two of the most popular web servers that work with these handlers: Apache and Nginx.

tagged: handlers webserver execute modcgi modphp modsuphp modfcgi phpfpm

Link: http://php.dzone.com/articles/get-handle-php-handlers

Three Devs & A Maybe Podcast:
Three Devs and a Aimee
Jan 19, 2015 @ 09:17:21

The Three Devs and a Maybe podcast has released their latest episode of their show - episode #54, Three Devs and a Amiee with hosts Michael Budd, Fraser Hart, Lews Cains and Edd Mann.

It is the first show of the new year! In this weeks episode we first reflect on how our holiday breaks went, and what happened to Edd's face?! Fraser's move up to Greenwich is next discussed, including how useful the taxi app 'Uber' is. We then move on to talk about Mick's experiences compiling Apache and PHP from source, along with CodeIgniter's decision to maintain 5.2 support. This leads on to conversation about the upcoming PHP UK Conference, along with tuning queries for the database query planner. Finally, we highlight the differences between Apache and nginx, along with their use of PHP-FPM.

Other topics mentioned include:

You can listen to this latest show either through the in-page audio player or by downloading the mp3 to listen whenever. If you enjoy the show, be sure to subscribe to their feed too.

tagged: threedevsandamaybe podcast ep54 holiday apache codeigniter phpuk nginx phpfpm

Link: http://threedevsandamaybe.com/three-devs-and-a-aimee/

Remi Collet:
PHP-FPM in Docker
Dec 12, 2014 @ 11:57:35

Remi Collet has a new post today showing you how to get PHP-FPM up and running with Docker using a few simple lines in the Dockerfile. Docker is a toolset that lets you easily create and provision containers with scripted configurations (and link them together).

[The] use case [for this is] running php 5.3.3 on a Fedora 20 / 21 development workstation, for production deployment on RHEL-6 (as no php 5.3 SCL exists). This example can be easily adapted for all available PHP versions available as RPM (5.3.3 in RHEL-6, 5.4.16 in RHEL-7, 5.4.16 and 5.5.6 in RHSCL 1.2 or using a third party repository).

The contents of the Dockerfile are included, making a call to yum to install all the needed packages, make a few replacements in the www.conf configuration file and create the default "www" directory. Finally, it fires up the PHP-FPM server with the IP given in the startup. The commands to create the container and launch it are also included in the post.

tagged: tutorial phpfpm docker container create configure

Link: http://blog.famillecollet.com/post/2014/12/11/PHP-FPM-in-Docker

Mattias Geniar:
The PHP circle: from Apache to Nginx and back
Nov 20, 2014 @ 10:26:28

In this new post to his site Mattias Geniar goes in circles...from Apache to Nginx and back in terms of how it relates to PHP.

As with many technologies, the PHP community too evolves. And over the last 6 or 7 years, a rather remarkable circle has been made by a lot of systems administrators and PHP developers in that regard.

He talks about the "early days" and the rise of Apache as the "A" in the LAMP stack. Then Nginx was created/released and PHP developers saw it as a viable option. He talks about how PHP worked with this server and the solutions that were found to "hack" them together. There were issues around the relationship, though, and - in the author's perspective - the circle has come back around to Apache, just with a bit more smarts about how it's configured.

tagged: circle apache webserver nginx opinion configuration phpfpm

Link: http://ma.ttias.be/php-circle-apache-nginx-back/

SitePoint PHP Blog:
How to Run Multiple Versions of PHP on One Server
Nov 07, 2014 @ 10:54:27

The SitePoint PHP blog has a new tutorial by Thien Tran Duy showing you how to run multiple versions of PHP all on the same server. The key is in using a few custom configuration options (you'll be compiling PHP manually for this) to place the different versions in different locations.

In this particular post, we’ll demo a solution to install multiple versions of Phalcon and PHP and run them on a single web server. PHP 5.5.x and 5.6.x will be used here, but you can replace them with other versions. Any servers that support PHP-FPM should be enough but we recommend using Nginx. The environment used in this tutorial is Fedora OS – a Linux system, but the instructions are almost identical for any other *nix OS.

The tutorial also includes the installation of a few other PHP extensions including APC caching, memcache and ioncube. He walks you through the installation of Nginx first to get the web server up and running. Then he starts in on the PHP installs and the requirements to ensure you have to be able to compile from the PHP source. He shows how to pull the different versions of PHP down (5.3, 5.4, 5.6 and master) from the GitHub repository and execute the "buildconf" to make the configure script. He includes the example configuration command with options, ensuring it will work with PHP-FPM and the Nginx server. He then reproduces the process, making slight changes, for the other versions of PHP. Finally, he shows the installation of the two different versions of Phalcon and configuring it to all work with the installed web server.

tagged: multiple version one server language tutorial phpfpm nginx

Link: http://www.sitepoint.com/run-multiple-versions-php-one-server/

PHP 5.4.28 Released
May 02, 2014 @ 10:06:22

The PHP development group has officially release the latest update for the stable PHP 5.4.x line - PHP 5.4.28.

The PHP development team announces the immediate availability of PHP 5.4.28. 19 bugs were fixed in this release, including CVE-2014-0185. All PHP 5.4 users are encouraged to upgrade to this version.

The CVE fix involves an issue around a PHP-FPM bug that could allow for privilege escalation due to default permissions. Users of previous releases in the PHP 5.4.x series and PHP-FPM are strongly encouraged to update to this latest release. You can download this release from the main downloads page (Windows users go here.

tagged: language release bugfix phpfpm cve20140185

Link: http://php.net/index.php#id2014-05-01-1