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

TutsPlus.com:
Boost Your Website Performance With PhpFastCache
Jun 05, 2018 @ 17:14:03

The TutsPlus.com site has a new tutorial posted showing you how to boost the performance of your PHP application with the help of PhpFastCache. PhpFastCache is a library that can either be installed manually or via Composer.

PhpFastCache is a library that makes it a breeze to implement caching in your PHP applications. It's an easy-to-use and yet powerful library that provides several APIs to help you implement a caching strategy of your choice without much hassle.

Don't make the mistake of assuming that it's merely a traditional file system caching scheme. In fact, PhpFastCache supports a plethora of adapters that let you choose from high-performance back-ends like Memcache, Redis, MongoDB, CouchDB, and others.

The article starts by helping you install (via Composer) and configure the library with the default file storage method. They talk you through all the code required to configure the caching and using the CacheManager to get and set values as well as checking to see if they're already cached. The tutorial also includes a bonus section showing how to use Redis for the storage rather than local file storage making it easier to share the cache data across multiple systems/servers.

tagged: tutorial phpfastcache caching tool library install configure implement

Link: https://code.tutsplus.com/tutorials/boost-your-website-performance-with-phpfastcache--cms-31031

Laravel News:
Laravel Model Caching
Jan 12, 2018 @ 15:16:25

On the Laravel News site they've posted a tutorial showing you how to use the caching functionality for models based on the framework's Eloquent ORM layer. This caching makes for fewer queries to the database and can improve the overall performance of the application.

You’ve probably cached some model data in the controller before, but I am going to show you a Laravel model caching technique that’s a little more granular using Active Record models. This is a technique I originally learned about on RailsCasts.

Using a unique cache key on the model, you can cache properties and associations on your models that are automatically updated (and the cache invalidated) when the model (or associated model) is updated. A side benefit is that accessing the cached data is more portable than caching data in the controller, because it’s on the model instead of within a single controller method.

They start with an example of it in action, getting the count of comments on a news article based on a relationship. It then shows the use of the touch method to change the model's updated_at timestamp to the current time allowing you to more correctly detect when changes occur. It also includes a more automatic way of performing the same operation using the $touches class property on the model and the cacheKey method to create a unique key name for use in the caching system to reference the model contents.

tagged: model caching laravel tutorial touch updatedat cachekey unique

Link: https://laravel-news.com/laravel-model-caching

Delicious Brains Blog:
Full Page Caching With Personalized Dynamic Content
Jan 03, 2018 @ 17:19:13

On the Delicious Brains site there's a tutorial posted by Ashley showing you how to set up full page caching with personalized dynamic content instead of the usual package caching of static content every user should see. The post is focused on improving the performance of a WordPress-based site.

We’ve talked a lot about WordPress performance here at Delicious Brains and the importance of page caching. However, implementing a page cache on highly dynamic sites or sites which display personalized content isn’t always easy. Previously, we’ve covered Microcaching for dynamic content, but that still doesn’t help when personalized content is involved.

In this article we’re going to tackle that issue. We’re going to use Easy Digital Downloads and the Themedd theme to build a fictitious online store. This will present us with a few problem areas that mean we can’t perform page caching out-of-the-box.

The tutorial starts by outlining the issues that come up with traditional caching tools and dynamic content. It then gets into the changes required to make it work with the Simple Cache plugin. It shows the code involved in splitting the caching functionality by generic, static page caches and how to inject the dynamic content cache back into the page when a user-specific resource is requested.

tagged: full page caching dynamic content wordpress tutorial inject

Link: https://deliciousbrains.com/page-caching-personalized-dynamic-content/

Olav van Schie:
Make your Laravel App Fly with PHP OPcache
Jun 14, 2017 @ 15:16:21

On his Medium site Olav van Schie shows you how to "make your Laravel app fly" with the help of OPcache. While OPcache isn't something that's specific to Laravel, he does include a package near the end that makes it easier to use it with the caching built into "artisan".

Every time you execute a PHP script, the script needs to be compiled to byte code. OPcache leverages a cache for this bytecode, so the next time the same script is requested, it doesn’t have to recompile it. This can save some precious execution time, and thus make your app faster (and maybe save some server costs).

He starts with a brief overview of OPcache and the main benefit it provides. He also shares some benchmarks he performed on a Digital Ocean server based on the results of performance testing the default Laravel "welcome" page. He then shows how to check and be sure it's installed and enabled on your PHP installation and some good default settings to configure in your php.ini. The post wraps up mentioning the package that helps integrate it with the Laravel application and the command required to clear out the OPcache on deploy.

tagged: laravel application opcache caching opcode performance tutorial

Link: https://medium.com/appstract/make-your-laravel-app-fly-with-php-opcache-9948db2a5f93

Delicious Brains Blog:
Microcaching WordPress in Nginx to Improve Server Requests by 2,400%
Apr 26, 2017 @ 15:18:40

The Delicious Brains has a new tutorial posted sharing a method you can use to setup microcaching in Nginx for your WordPress installation and improve the performance of server requests by a large margin.

We’ve talked a lot about WordPress performance and hosting WordPress here at Delicious Brains. A common theme amongst those articles is the importance of page caching and how it’s arguably the best way to improve the performance of your WordPress site. [...] However, we’ve also alluded to the fact that page caching is difficult to implement on highly dynamic sites.

[...] In these circumstances page caching still has its place but the duration of the cache has to be significantly reduced. This is known as microcaching. Microcaching is a technique where content is cached for a very short period of time, usually in the range of 1-10 seconds. In this article, I’m going to demonstrate how to configure WordPress and bbPress with Nginx FastCGI caching.

They start off with some initial benchmarks performed using the Blitz.io service against a clean WordPress install on a Digital Ocean droplet. The first results are of a test with 100 concurrent users over 60 seconds (with not so great results). Then, using this method in the Nginx configuration, the site is retested resulting in much better performance but with one downfall - the pages are cached and no longer dynamic.

To resolve this they move to the "microcaching" solution, adding the caching to parts of the application that aren't the forum using the "X-Accel-Expires" header sent from WordPress. The post ends with a bit more tweaking to the configuration and some caveats to its use.

tagged: wordpress caching microcaching nginx tutorial dyanmic benchmark

Link: https://deliciousbrains.com/microcaching-wordpress-nginx-improve-server-requests-2400/

Thijs Feryn:
My Varnish book is now available (O'Reilly)
Feb 16, 2017 @ 18:43:25

If you've ever been interested in using Varnish as a caching layer for your application but weren't sure where to start, you're in luck. In a post to his site Thijs Feryn has announced the release of his book covering Varnish and helping you get started integrating it into your infrastructure.

I’m proud to announce that my Varnish book is out now. It’s called “Getting Started With Varnish Cache” and it’s available for download through Varnish Software. For the next 30 days, Varnish Software has the exclusive rights to distribute the book. After that, O’Reilly will also be distributing physical copies and the digital version of the book, while Varnish Software will continue to distribute the book on their website.

Varnish Software is currently offering the book for free (well, "free" after you give your personal info). Thijs gets into a bit of detail around the book, the process he followed creating it and what kinds of things Varnish can help with. He points out that it was "one hell of a ride" writing the book and getting it published but notes that it was a "fun experience" and probably won't be the last book he writes.

tagged: varnish caching book oreilly process contents benefits

Link: https://blog.feryn.eu/my-varnish-book-is-now-available/

CloudWays Blog:
Using Memcached With PHP
Apr 13, 2016 @ 18: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/

Laracasts Snippet:
Episode 14 - Russian-Doll Caching in Laravel
Feb 15, 2016 @ 16:22:05

The Laracasts Snippet podcast has posted their latest episode with a brief look at Russian-doll caching in Laravel.

One of the things I've been tinkering with these last few days is a mechanism for performing Russian-Doll caching in Laravel. In addition to determining if I can even make it work, I've been pondering whether this truly has a place in your future projects, or if there simply isn't enough value to warrant its usage. Who knows - let's talk about it.

The podcast also links to this series of posts on the Laracasts site on the subject. If you'd like to listen to this podcast, though, you can use either the in-page audio player or you can download the mp3 of the show. If you enjoy it, be sure to subscribe to their feed too.

tagged: laracasts snippet podcast ep14 russiandoll caching

Link: https://laracasts.simplecast.fm/14

SitePoint PHP Blog:
Caching Hat-trick: Zend Opcache, Etags and Query Caching
Jul 13, 2015 @ 14:57:56

The SitePoint PHP blog has posted three tips on caching that can help speed up your application from the processing level up. The article shares tips on using opcode caching for faster processing, etags for web request caching and query caching on the data side.

In this article, we will be looking at some of the common caching techniques in PHP: Opcache, Expires Headers and Query Caching in MySQL. We’ll look at additional approaches in part 2.

He starts with an introduction to the request lifecycle of a typical request made to a PHP-based application, from the fetching of a file to the actual execution. This lays the groundwork for the first kind of caching: opcodes for caching execution results. He helps you get that enabled and configured and shows how to determine how much it's actually helping. Following this he talks about the "expires" headers you can send from Apache, telling the browser exactly when it needs to fetch new versions of things like CSS, image or Javascript files. Finally he touches on MySQL query caching, storing the already parsed version of a query on the server with results in a cache for faster polling on repeated requests.

tagged: caching zend opcode etags expires query caching tutorial speed performance

Link: http://www.sitepoint.com/caching-hat-trick-zend-opcache-etags-and-query-caching/

SitePoint PHP Blog:
Caching Hat-trick: Zend Opcache, Etags and Query Caching
Jul 13, 2015 @ 14:57:56

The SitePoint PHP blog has posted three tips on caching that can help speed up your application from the processing level up. The article shares tips on using opcode caching for faster processing, etags for web request caching and query caching on the data side.

In this article, we will be looking at some of the common caching techniques in PHP: Opcache, Expires Headers and Query Caching in MySQL. We’ll look at additional approaches in part 2.

He starts with an introduction to the request lifecycle of a typical request made to a PHP-based application, from the fetching of a file to the actual execution. This lays the groundwork for the first kind of caching: opcodes for caching execution results. He helps you get that enabled and configured and shows how to determine how much it's actually helping. Following this he talks about the "expires" headers you can send from Apache, telling the browser exactly when it needs to fetch new versions of things like CSS, image or Javascript files. Finally he touches on MySQL query caching, storing the already parsed version of a query on the server with results in a cache for faster polling on repeated requests.

tagged: caching zend opcode etags expires query caching tutorial speed performance

Link: http://www.sitepoint.com/caching-hat-trick-zend-opcache-etags-and-query-caching/


Trending Topics: