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

CloudWays Blog:
Using Memcached With PHP
Apr 13, 2016 @ 13:48:10

On the Cloudways blog they have a new tutorial posted showing you how to use memcached with PHP to help improve the overall performance of your application through cached data.

Memcached is a distributed memory caching system. It speeds up websites having large dynamic databasing by storing database object in Dynamic Memory to reduce the pressure on a server whenever an external data source requests a read. A memcached layer reduces the number of times database requests are made.

[..] Why Memcached? It increases the response time of your web pages, which in return enhances the overall customer’s experience. A better response time allows users to fetch data seamlessly.

He starts by ensuring that you already have a memcached instance up and running (it's external to PHP). They suggest using their own Cloudways setup, but it's relatively easy to install with packages on most Linux distributions. With that verified, he shows how to check for memchace functionality in your PHP installation and provides a bit of code to create a connection. Next is an example showing how to pull information from a MySQL database and push that data directly into the waiting memcache server via a set method call. It also includes a get example, showing if the caching was a success or not.

tagged: memcached caching tutorial introduction server configuration example

Link: http://www.cloudways.com/blog/memcached-with-php/

Oracle Coherence Blog:
Getting Started With The Coherence Memcached Adaptor (and PHP)
Aug 20, 2014 @ 10:55:45

As Chris Jones mentions in his latest post to his OTN blog, there's a tutorial that's been posted by David Felcey showing how to get started with Oracle Coherence via the memcached adapter in PHP. Coherence is Oracle's own version of a key/value storage that focuses on performance and scalability.

Coherence 12c (12.1.3) adds support for Memcached clients to directly store data a in Coherence cluster using the Binary Memcached protocol. This post outlines how to configure the Coherence Memcached Adaptor and includes a simple PHP example to show how Memecached clients can connect to a Coherence cluster.

He includes the XML configuration you'll need to create/modify on the Oracle side to make the memcached connections work and explains the different parts. With that in place, he moves on to the PHP example, showing a simple memcached request to store and retrieve a string. It's almost transparent to the PHP user save some of the configuration options required to make it work.

tagged: oracle coherence introduction memcached adapter tutorial

Link: https://blogs.oracle.com/OracleCoherence/entry/getting_started_with_the_coherence

Mikko Koppanen:
Memcached protocol support
Nov 15, 2013 @ 11:15:38

Mikko Koppanen has posted about some updates he's making to the PECL memcached extension, more specifically around binary protocol support.

There are quite a few things still missing and only binary protocol is supported at the moment, but the code seems to work reasonably well in small-scale testing. I am not sure whether this is useful for anyone, but at least it allows things such as quick prototyping of network servers, exposing sqlite database over memcached protocol etc.

An example of code using this new functionality is included in the post showing how to create both a simple sever with attached "get" and "set" handlers and a client to connect to it and enable the binary protocol.

The code is still work in progress but it’s available in github: https://github.com/mkoppanen/php-memcached/tree/feature-server. Note that you need to compile libmemcached with –enable-libmemcachedprotocol and the PECL memcached extension with –enable-memcached-protocol.
tagged: memcached binary support protocol pecl update

Link: http://valokuva.org/memcached-protocol-support/

PHP Performance Crash Course, Part 2: The Deep Dive
Nov 13, 2013 @ 10:56:33

DZone.com has posted the second part of a two-part series looking at increasing the performance of your PHP applications (part one is here). In this new post, he looks at a few topics including caching, session handling and asynchronous processing with Resque and Redis.

Ultimately, scalability is about the entire architecture, not some minor code optimizations. Often times people get this wrong and naively think they should focus on the edge cases. Solid architectural decisions like doing blocking work in the background via tasks, proactively caching expensive calls, and using a reverse proxy cache will get you much further than arguing about single quotes or double quotes.

He briefly recaps some of the "core principles" for optimizing applications and gets right into explaining the later ones on the list:

  • Optimize sessions through memcached handling
  • HTTP request/response caching
  • Caching Doctrine result sets
  • Caching the web service responses made with Guzzle
  • Handling asynchronous processing with Resque and Redis

He includes code and configuration examples for each item, helping to flesh them out a bit more. He also makes a recommendation of using something like AppDynamics to monitor the performance of your application (disclaimer: he works for them).

tagged: performance crash course part2 series caching redis memcached session

Link: http://architects.dzone.com/articles/php-performance-crash-course-0

Aleksey Korzun:
Benchmarking Memcached and Redis Clients
Jun 19, 2013 @ 11:06:31

Aleksey Korzun has posted some of the results from benchmarking he performed on various Memcached and Redis clients through PHP. His tests focused on multiple PHP client libraries, both user-land and extension based.

As some of you may know, I’m crazy about speed. So when I saw that people were happily using Predis as their choice of PHP client for Redis, I was a bit confused. Why use a client written in PHP for something that should be ‘fast’ like Redis? That kind of defeats the purpose - unless you don’t really care about response times and scalability. [...] The performance difference piqued my interest. I wanted to find out just how much performance users are sacrificing by choosing one implementation over another.

He ran his tests on VirtualBox VM instances with the same specs and the same version of PHP installed. He tested various versions of the Memcached client, Redis client, Predis and the IgBinary extension. His results (Google spreadsheet) show the requests processed using each method based on this benchmarking script.You can visit the post to see the graphs of the results too.

tagged: benchmark memcached redis client graph results

Link: http://alekseykorzun.com/post/53283070010/benchmarking-memcached-and-redis-clients

James Fuller:
Simply scale with Nginx, Memcached, PHP-FPM and APC
Feb 04, 2013 @ 10:46:01

James Fuller has posted a guide to scaling your web application using the nginx web server, memcached, PHP-FPM and APC caching.

We sell an educational product that serves a predictable 15,000 requests per minute for 10+ hours/day, every day. Instead of Apache, we use nginx with PHP-FPM to handle this traffic. This is becoming a very popular setup for many companies with non-trivial traffic, but I have also found success with it in my small 256MB Ram VPS. For various reasons, nginx does a better job with memory and concurrent connection handling than Apache. In this post, I want to talk about some of the reasons you might want to go with this setup.

He talks about some of the efficiency gains that memcache and nginx can give you pretty easily and some of the common uses for nginx, including using it as a reverse proxy. He talks some about Apache's typical request handling and shows the difference between that and how nginx does its "never block, finish fast" handling. He fits in the other pieces - PHP-FPM, memcached and APC - showing how each of them offers their own types of performance gains for different areas of the application.

tagged: scale platform nginx memcached phpfpm apc cache


Mike Purcell's Blog:
CentOS - PHP - Install Memcached (with a d) Stack
Jun 20, 2012 @ 09:13:59

In this new post to his blog Mike Purcell gives you the full instructions to getting a CentoOS 6 system up and running with Memcached and PHP.

Recently I started retro-fitting the MeLikeDrinks.com drink website to cache frequently used data to improve performance, as such I wrote a light, custom cache API which sits on top of PHP’s Memcached API. [...] If you opt to use PHP Memcache, and because this article assumes you are using CentOS, you can simply have YUM install the entire stack for your via `yum install php-memcache`.

He describes some of the differences between the two memcache APIs available to PHP developers (memcache and memcached) and includes the instructions to get both versions installed. "Memecache" is as easy as installing the package, while "Memcached" takes a bit more work - installing dependencies, configuring and compiling a few things specific to your system.

tagged: memcached install centos package compile tutorial


Artur Ejsmont's Blog:
Publishing queue messages from PHP using different backends
Mar 26, 2012 @ 11:31:53

Artur Ejsmont has a new post sharing some benchmarks he put together about the "messages per second" and "time to execute" when using PHP to pull from various messaging backends.

I have looked at the state of different messaging backends recently and i ran a little benchmark to see what is the rough comparison of message publishing throughput. Results that i got are quite surprising. What i wanted to achieve is some sort of reassurance before choosing a messaging bus for my PHP project.

Running both the PHP and the messaging test scripts on the same server, he pulled from a few different backend systems - RabbitMQ, MySQL, MongoDb, Memcached and ActiveMQ. The results were interesting, showing an interesting result in the time it took to execute versus the number of messages per second pushed in.

tagged: benchmark message queue backend rabbitmq mysql mongodb memcached activemq


Turbocharge your Website with Memcached
Feb 07, 2012 @ 10:06:40

On the NetTuts.com site there's a new tutorial showing you how to introduce the Memcached tool to your application - a quick and easy way to cache data and optimize performance.

Your latest PHP/MySQL website is finally online. And it’s awesome. But it’s not as fast as you want it to be, because of the many SQL queries running every time a page is generated. And above that, you have the feeling it will not scale well under heavy loads. And you are most likely right. In this tutorial, we will see how you can greatly improve your website’s responsiveness [...] by implementing a cache layer between your code and your database. The good news is it is fairly easy, and can be done in a few minutes!

They help you get the memcached server installed (a one-liner in most linux distributions) and how to install the memcached extension using PECL. Code is included showing you how to connect to the server, store data into the cache based on a generated key and how to pull the same data back out.

tagged: memcached cache data tutorial introduction


Maarten Balliauw's Blog:
Running Memcached on Windows Azure for PHP
Oct 24, 2011 @ 21:52:11

Maarten Balliauw has a new post to his blog with a guide to running mamcached on Windows Azure for PHP, a tool targeted towards PHP on Windows users to provide them with the ability to cache outside of their application.

While Windows Azure offers a distributed caching layer under the form of the Windows Azure Caching, that components currently lacks support for non-.NET technologies. I’ve heard there’s work being done there, but that’s not very interesting if you are building your app today. This blog post will show you how to modify a Windows Azure deployment to run and use Memcached in the easiest possible manner. Note: this post focuses on PHP but can also be used to setup Memcached on Windows Azure for NodeJS, Java, Ruby, Python...

He provides a phar-based scaffolding you can use to set up the instance and describes two ways of accomplishing it - the "short way" of relying on the scaffolding or the "long way" describing what the scaffolder does behind the scenes (complete with code). For this, you can also download the source and look through it.

tagged: windows azure memcached caching tool tutorial