This project is read-only.
Home | Setup Guide | Deployment Guide | Advanced Features

PHP Worker Role


Most of the time PHP developers will use the Windows Azure Web Role for developing and deploying PHP Web Applications. However, there might be a need to execute PHP scripts as background tasks on Windows Azure. This has to be done within a Windows Azure Worker Role. The entrypoint of any WorkeRole has to be written as managed code. PHP background scripts need to be invoked from the managed code. In order to abstract the managed code and invocation from PHP developers, the Windows Azure Command-line Tool for PHP provides a prebuilt managed dll (WorkerRole.dll) that performs the necessarry operatons to invoke the PHP script. In addition to running backgroud tasks, the Worker Role can also run a web-server by executing the IIS Hosted Web Core from the worker process. The Hosted Web Core provides more control over the FastCGI settings than the traditional web-role does (such as control over request timeout internal).

Command Line Syntax

The following command-line entry builds a deployment package MyProject with Worker role and Worker role start up script within local host's TEMP directory and deploys to local Development Fabric:

Using short parameters:

 C:\...\WindowsAzureCmdLineTools4PHP>php package.php 
    -r="C:\Program Files\PHP\" 

Using long parameters:

 C:\...\WindowsAzureCmdLineTools4PHP>php package.php 
    --phpRuntime="C:\Program Files\PHP\" 

The parameters provided for this run are:
  • --project (-n) - Create deployment package with this project name: testBoth
  • --phpRuntime (-r) - Include PHP runtime from .
  • --worker-role (-w)- Include the Worker role application from .
  • --worker-role-startup-script (-b)- Include Worker role start up script from.
  • --scheduled-task-duration (-q)- Duration of invoking the Worker role start up script.
  • --hosted-web-core (-e)- Include Hosted Web Core application from
  • --runDevFabric (-u) - Enable deployment of package into Dev Fabric.
  • --cleanRebuild (-f) - Perform complete rebuild of package and support directories.

The following link presents a verbose run of command-line with the aforementioned parameters:

C:\...\WindowsAzureCmdLineTools4PHP > php package.php -n=testSimple -r="C:\Program Files\PHP"  -w="E:\webapps" -b="test\test.php" -q="00:00:10" -uf


  1.     Validating parameters.

  2.      Validating Tool's PHP Resource. .

  3.      Validating Workspace. . .

  4.      Start building project "testSimple"

  5.      Validating PHP Sources for WebRole directory.

  6.      Removing "testSimple" Service if deployed upon Dev Fabric. . . .

  7.      Creating clean workspace for "testSimple". . . . . .

  8.      Adding resources to Web Role. . . . . . . . .

  9.      Adding resources to Service Directory.

  10.     Configuring "testSimple" Web Role. . . 

  11.     Validating Worker Role Source directory.

  12.     Validating Worker Role Start Up Script Path. 

  13.     Validating Start Up Script Time Duration. 

  14.     Creating Worker Role Directory. . . 

  15.     Start building package for project "testSimple" 

  16.     Validating Web.config's Default Document exists. 

  17.     Packaging "testSimple" Web Role. . . 

  18.     Validating Service Directory. 

  19.     Configuring "testSimple" Service. . 

  20.     Packaging "testSimple" Service. . . 

  21.     Successfully packaged "testSimple"


"testSimple" Web Role is ready for development.

WebRole Location:



"testSimple" Deployment Package and Configuration is ready.

Package Location:


WebRole Package: testSimple.cspkg

Service Package: ServiceConfiguration.cscfg


  22.     Start Dev Fabric deployment of project "testSimple"

  23.     Deploying "testSimple" Service upon Dev Fabric. . . . . . . . . . . 


"testSimple" Web Role is running in Dev Fabric.

Deployment ID: 587

Endpoint URL:

Success: Normal Exit

When command-line tool runs, it performs the following:
  1. Validates that you have the necessary resources downloaded into the "<install location>\res\php\" directory.
  2. Since user did not provide a workspace using --target (-t), the tool will by default create a workspace within the user's TEMP directory:
    1. C:\Users\username\AppData\Local\Temp\WACmdLineTools\
  3. Tool creates three directories within this workspace:
    1. WebRole directory - Contains PHP sources to be packaged, which is located:
      1. C:\Users\username\AppData\Local\Temp\WindowsAzureCmdLineTools4PHP\testSimple_Build\testSimple_WebRole
    2. Service directory -Workspace for packaging WebRole contents, which is located:
      1. C:\Users\username\AppData\Local\Temp\WindowsAzureCmdLineTools4PHP\testSimple_Build\testSimple
    3. WorkerRole directory - Contains Worker role application and PHP sources to be packaged, which is located:
      1. C:\Users\username\AppData\Local\Temp\WindowsAzureCmdLineTools4PHP\testSimple_Build\testSimple_WorkerRole
  1. Since user did not provide sources using --source (-s), then tool will copy from its downloaded resources the following default contents into aforementioned tool created WebRole directory. The default provided contents includes the following files:
    1. index.php: Simple execution of PHP function phpinfo().
    2. Web.config: Defines index.php as the default web site document.
  2. Downloads from a Windows Azure account all necessary PHP resources to create deployment package.
  3. Tool creates from all PHP sources provided within WebRole directory into a Windows Azure deployment package within Service directory: The result of this packaging includes:
    1. testSimple.cspkg – Package of WebRole's PHP sources, Worker role application, Worker role start up script, duration of start up script and required PHP resources to run web application upon Windows Azure Platform.
    2. ServiceConfiguration.cscfg – Configures how to service the deployed WebRole and Worker Role within Windows Azure Platform.
  4. With --runDevFabric (-u) parameter provided, then the tool deploys the packaged WebRole and Worker role upon the local Development Fabric. The deployment will find the next available port of localhost's IP address For example, if port 81 is already taken, then Development Fabric will deploy WebRole to localhost's port 82:

Last edited Sep 14, 2010 at 8:06 PM by suchawla, version 5


No comments yet.