| 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.
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:
Using long parameters:
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.
- --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.
"testSimple" Deployment Package and Configuration is ready.
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: http://127.0.0.1:82/
Success: Normal Exit
When command-line tool runs, it performs the following:
- Validates that you have the necessary resources downloaded into the "<install location>\res\php\" directory.
- Since user did not provide a workspace using --target (-t), the tool will by default create a workspace within the user's TEMP directory:
- Tool creates three directories within this workspace:
- WebRole directory - Contains PHP sources to be packaged, which is located:
- Service directory -Workspace for packaging WebRole contents, which is located:
- WorkerRole directory - Contains Worker role application and PHP sources to be packaged, which is located:
- 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:
- index.php: Simple execution of PHP function phpinfo().
- Web.config: Defines index.php as the default web site document.
- Downloads from a Windows Azure account all necessary PHP resources to create deployment package.
- 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:
- 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.
- ServiceConfiguration.cscfg – Configures how to service the deployed WebRole and Worker Role within Windows Azure Platform.
- 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 http://127.0.0.1. For example, if port 81 is already taken, then Development Fabric will deploy WebRole to localhost's port 82: