Ruslan YakushevHow to warm up Azure Web App during deployment slots swap (30.9.2015, 16:23 UTC)

Azure Web App deployment slots are used to help roll out new versions of an app without downtime or cold start activation. New version is typically deployed to a staging slot, then after testing and final verification it gets swapped into a production slot. During the swap operation the Web App’s worker process may get restarted in order for some settings to take effect. Even though the swap does not proceed until the restarted worker process comes back online on every VM instance, it may still not be enough for application to be completely ready to take on production traffic. This post explains how you can use the recently enabled Application Initialization Module to completely warm up your application prior to swapping it into production.

First of all it is necessary to explain the sequence of actions that happens when a staging slot is swapped into production. When the Swap button is clicked in Azure Portal or a corresponding management API is called:

  1. The App Settings and Connection Strings that are marked as “Slot” are read from the Production slot and applied to the site in the Staging slot. That causes the site’s worker process to be restarted for those changes to take effect and become visible as process environment variables;
  2. Then the site in the staging slot gets warmed up. To warm up the site an HTTP request is made to the root directory of the site to every VM instance where site is supposed to run. The warm up request has a User-Agent header set to “SiteWarmup”;
  3. After warm up has completed the host names for the sites in production and staging slots get swapped. Now the site that has been warmed up in the staging slot starts getting production traffic and the site that used to be in the production slot is now in the staging slot
  4. The site that is now in the staging slot gets updated with the App Settings and Connection Strings associated with the staging slot. That causes restart of that site, but it is not in production slot any more so restart is harmless.

Sometimes hitting the site’s root URL is not enough to completely warm up the application. For example it maybe necessary to hit all important routes in an ASP.NET MVC app or to pre-populate the in-memory cache. That is where the Application Initialization Module can help.

Let’s use a simple example to demonstrate how a Web App can be warmed up in the deployment slot during the swap operation. First let’s create a site and a staging deployment slot:

Next let’s set some slot settings on the App and its staging slot. These slot settings will cause the App’s worker process to restart during swap.

For the actual app code I used two simple PHP files: index.php and warmup-cache.php. The index.php is served when site’s root URL is requested. The warmup-cache.php is my “cache warmup” code that takes long time to run (emulated by sleep() command). In real application that can be the script that makes database queries to fill up the cache.

Finally I also have a web.config file which configures AppInit module:

<applicationInitialization >
<add initializationPage="/warmup-cache.php" hostName=""/>

In the applicationInitialization section I can specify multiple URL paths that need to be requested in order to warm up my application. In my case I only need to hit one URL. Also notice that I can specify the host name to use for the warm up requests (this is optional and if not specified the “localhost” will be used as a host name).

To confirm that the warmup-cache.php is actually requested during the swap I will use Failed Request Tracing. It can be enabled from Azure Portal:

Truncated by Planet PHP, read more at the original (another 4256 bytes)

SitePoint PHPPHP Channel’s 3rd 2015 Trimester Update (30.9.2015, 16:00 UTC)

Another three months have gone by, and we’ve got some news to share.

First, let’s introduce our newest authors!

People coming towards camera, silhouettes visible

New Authors

Jeff Smith Profile Image Jeff Smith, USA

Jeff Smith is a full-stack web developer who enjoys writing and reading of all types, and is interested in the Internet, business and entrepreneurship, technology, and learning new stuff. Jeff has been a very active member of our forums for a while now, and decided to chime in with his opinions by writing about defensive programming in PHP.

His debut post was well received, and part two is coming soon. In fact, it’s already in our peer review queue, so if you’d like to take an early look and give us your opinion on it, our doors are wide open!

Continue reading %PHP Channel’s 3rd 2015 Trimester Update%

Lorna MitchellNew in PHP 7: null coalesce operator (30.9.2015, 12:23 UTC)

Not the catchiest name for an operator, but PHP 7 brings in the rather handy null coalesce so I thought I'd share an example.

In PHP 5, we already have a ternary operator, which tests a value, and then returns the second element if that returns true and the third if it doesn't:

echo $count ? $count : 10; // outputs 10

There is also a shorthand for that which allows you to skip the second element if it's the same as the first one:

In PHP 7 we additionally get the ?? operator which rather than indicating extreme confusion which is how I would usually use two question marks together instead allows us to chain together a string of values. Reading from left to right, the first value which exists and is not null is the value that will be returned.

// $a is not set
$b = 16;

echo $a ?? 2; // outputs 2
echo $a ?? $b ?? 7; // outputs 16

This construct is useful for giving priority to one or more values coming perhaps from user input or existing configuration, and safely falling back on a given default if that configuration is missing. It's kind of a small feature but it's one that I know I'll be using as soon as my applications upgrade to PHP 7.

New in PHP 7: null coalesce operator was originally published on LornaJane by Lorna. Lorna is a web development consultant, tech lead, author, trainer, and open source maintainer, and she is occasionally available for freelance work.

PHP ClassesGet Twitter Direct Message Images in PHP with the OAuth API (30.9.2015, 07:33 UTC)
By Manuel Lemos
Twitter API allows applications to access users' direct messages but if you want to download images or other media associated with those direct messages, there is no specific API call to do so.

Direct messages are private, so there is no public URL to access the direct messages' images without using OAuth or you are a real logged user accessing Twitter via a browser.

Read this article to learn how to download images that belong to direct messages using authenticated requests with this PHP OAuth client class.
David SklarDegrees of Freedom (30.9.2015, 04:00 UTC)

What do you think the following PHP snippet outputs?

$temperature = 74;
print "It is $temperature°F right now.";

Cal EvansInterview with Chris Spruck (29.9.2015, 05:00 UTC) Link
PHP ClassesReview: Learning PHP Design Patterns (29.9.2015, 03:13 UTC)
Learning PHP Design Patterns
Alexander Skakunov
PHP books
William Sanders
I would recommend this book to those who are familiar with PHP architecture advanced issues to learn more about the listed design patterns and actually see how they can be applied in order to build a simple multi-device CMS.

Those who are not familiar with design patterns might find this book hard to digest.
Official Blog of the PEAR Group/PEAR PresidentPEAR 1.10.0dev3 is out (28.9.2015, 18:17 UTC)

PEAR 1.10.0dev3 – the probably last pre-release version before PEAR 1.10.0 stable appears – has been released.

It fixes the following bugs:

  • #20507: pear list-upgrades does not take PHP version into account [cweiske]
  • #20927: Use correct php-config [cweiske]
  • #20946: PEAR_Builder::log() declaration [remicollet]

You can download it here:

Upgrading your existing installation is also easy:

$ pear upgrade PEAR-1.10.0dev3
SitePoint PHPFlexible and Easily Maintainable Laravel + Angular Material Apps (28.9.2015, 16:00 UTC)

In this article, we’re going to set up a Laravel API with Angular Material for the front end. We’re also going to follow best practices that will help us scale with the number of developers working on the project and the complexity behind it. Most tutorials cover this topic from another perspective - they completely forget about scaling. While this tutorial is not targeted at small todo apps, it is extremely helpful if you’re planning to work with other developers on a big project.

Laravel angular material

Here’s a demo built with Laravel and Angular Material.

Setting up Laravel

Creating a project

We’re going to start by pulling in the latest Laravel - 5.1 at the time of writing.

composer create-project laravel/laravel myapp --prefer-dist

Configuring the environment

All the consequent commands will be ran inside the myapp directory. Throughout the remainder of this tutorial, we’ll assume you’re running a Linux environment if you’re following along. If you aren’t you’re encouraged to install Homestead Improved as a virtual Linux environment in which to follow along.

cd myapp

Next, we’re going to update our .env file with the database connection credentials:


Once your app has been configured, you should see the Laravel 5 greeting page.

Laravel 5

Continue reading %Flexible and Easily Maintainable Laravel + Angular Material Apps%

Thijs FerynInterviewing Kristof De Jaeger and discussing Drupal 8 & Drupalcon (28.9.2015, 11:05 UTC)

Last week I had the privilege to chat with Kristof De Jaeger (AKA @swentel on Twitter) at Drupalcon in Barcelona. I

The post Interviewing Kristof De Jaeger and discussing Drupal 8 & Drupalcon appeared first on Thijs Feryn's blog.

LinksRSS 0.92   RDF 1.
Atom Feed   100% Popoon
PHP5 powered   PEAR
ButtonsPlanet PHP   Planet PHP
Planet PHP