Powerpoint exploring the locations used in television show Time Clash
PHP on Windows and on Azure
1.
2. PHPon Windowsand on Windows Azure Maarten Balliauw – RealDolmenE-mail: maarten.balliauw@realdolmen.comBlog: http://blog.maartenballiauw.beTwitter: @maartenballiauw
3. Who am I? Maarten Balliauw Antwerp, Belgium www.realdolmen.com Focus on web ASP.NET, ASP.NET MVC, PHP, Azure, VSTS, … MVP ASP.NET Interested in interoperability PHPExcel, PHPLinq, Windows Azure SDK for PHP, ... http://blog.maartenballiauw.be http://twitter.com/maartenballiauw
4. Agenda Why PHP matters… PHP on Windows PHP on Windows Azure
5. Before we start… Much information! Slides decorated with topic: PHP on Windows PHP on Windows Azure
13. PHP 5.3 on Windows Is the most significant update to PHP on Windows! All libraries updated to latest versions (in some cases newer versions that used on Linux) Re-write of the build system from scratch Top PHP Windows community programmer working for Microsoft (Pierre Joye) Build with VS 2008 Available in 32 and 64 bit version Created windows.php.net 99% of all POSIX calls changed to native Windows calls
14. By the numbers: Running PHPBench looped 5x Both computers are a HP 8 core (2 procs x Quad core) 16gb ram. Linux (Centos 5.2) vs. Windows Server 2008 x86 NOTE: phpbench onlytests internal PHP engineperformance. It doesnot do IO of any kind.
15. Core is not everything… Other initiatives Web Platform Installer FastCGI on IIS Wincache extension SQL Server driver for PHP SDK’s (a lot!) Tooling
17. Easy installation of YOUR environment Easy installer providing Platform installation (IIS, extra modules, configuration, …) Both ASP.NET and PHP Application installation Both ASP.NET and PHP Publish your app through WebPI http://microsoft.com/web
20. PHP on Windows – History IIS support has been there for a long time Apache runs on Windows as well But… IIS gives best performance on Windows Unfortunately the choice was always between stability and performance…
25. IIS execution pipeline Since your PHP app is part of the IIS execution pipeline… …you can use IIS URL rewriting …you can use IIS as a load balancer (ARR) www.vipriva.com …you can use any .NET HttpModule out there ASP.NET membership / authentication Output caching …
30. Windows Cache Extension (“WinCache”) PHP module for 5.2 and 5.3 IIS specific PHP accelerator So only works in IIS! No code modifications needed in your application PHP functions to obtain information about the cache status http://www.iis.net/download/WinCacheForPhp
31. Cache layers Bytecode cache Caches compiled PHP scripts Script cache Cache script sources in memory to reduce I/O access and UNC file share access Relative file path cache Caches relative file path Session cache Sessions stored in shared memory
34. SQL Server Driver for PHP PHP extension for Windows So only works on Windows! Reliable, scalable and fast integration with SQL Server for PHP Relies on the Microsoft SQL Server Native Client to communicate with SQL Server.
35. PDO support SQL Server Driver for PHP v2.0 Support for PHP Data Objects (PDO) Better UTF-8 support Example: Drupal 7 on SQL Serverhttp://www.commerceguys.com/about/news/drupal-7-sql-server-preview
37. Using the SQL Server Driver for PHP Connecting $connection = new PDO('sqlsrv:server=.QLEXPRESS;database=blog');
38. Using the SQL Server Driver for PHP Querying class Post { public $Id; // ...} $posts = array(); $query = 'SELECT * FROM posts ORDER BY PubDate DESC'; $statement = $connection->query($query); while ( $row = $statement->fetchObject('Post') ) { $posts[] = $row; }
41. Microsoft and PHP = LOTS of goodies Some highlights… SQL Server Reporting Services SDK for PHP OData SDK for PHP Windows Azure Tools for Eclipse Windows Azure SDK for PHP AppFabric SDK for PHP Windows Azure Command-Line Tools for PHP Eclipse Tools for Silverlight Information Cards for PHP Internet Explorer Webslices and Accelerators for PHP PHP and Silverlight SQL CRUD Application Wizard for PHP Toolkit for PHP and Bing Maps Overview: http://www.interoperabilitybridges.com/
42. SQL Server Reporting Services SDK for PHP SSRS? Reporting tool in SQL Server Very powerful! Various output formats Can be linked to MySQL, PostgreSQL, … API to interoperate with SQL Server Reporting Services List available reports within a PHP applications, Provide custom parameters from a PHP web form, Manage the rendering of the reports within a PHP application http://ssrsphp.codeplex.com
43. OData SDK for PHP OData? Open Data Protocol Unlock your data and free it from silos that exist in applications today Builds on HTTP, AtomPub and JSON RESTful interface Way data is delivered in MS CN “Dallas” API to OData Generate proxy classes to OData feeds CRUD on OData feeds http://odataphp.codeplex.com/
44. OData SDK for PHP /* connect to the OData service */ $svc = new NorthwindEntities(NORTHWIND_SERVICE_URL); /* get the list of Customers in the USA +the list of Orders */ $query = $svc->Customers() ->filter("Country eq 'USA'") ->Expand('Orders'); $customerResponse = $query->Execute(); /* get only CustomerID and CustomerName */ $query = $svc->Customers() ->filter("Country eq 'USA'") ->Select('CustomerID, CustomerName'); $customerResponse = $query->Execute(); /* create a new customer */ $customer = Customers::CreateCustomers('channel9', 'CHAN9'); $proxy->AddToCustomers($customer); /* commit the change on the server */ $proxy->SaveChanges();
45. Windows Azure Microsoft’s Cloud Computing offering Web/worker role (= virtual machine) Blobs, tables, queues, drives (= storage) SQL Azure (= +/- SQL Server) AppFabric (= access control & firewall punching) “Dallas” (= Data-as-a-Service) Working with PHP Windows Azure Tools for Eclipse Windows Azure SDK for PHP AppFabric SDK for PHP Windows Azure Command-Line Tools for PHP Zend Framework contribution More on this: later today!
52. Summary PHP on Windows is a priority for Microsoft Full range of PHP support Products and Services Attract more customers to the MS platform through world-class support and resources Microsoft wants you to succeed
68. The Windows Azure Platform Windows Azure SQL Azure Windows Azure platform AppFabric Microsoft Codename “Dallas” Microsoft Codename “Sydney” Developer tools
70. Windows Azure Flexible application hosting Lights-out service management Provide code & service model, hit ENTER Storage at massive scale Blobs, tables, queues Compute Storage Management There’s an SDK for this: http://phpazure.codeplex.com
71. Storage options Blobs, tables, queues Windows Azure Drive (a.k.a. Xdrive) Virtual NTFS volume that can be mounted .vhd format Use existing NTFS API’s Easier migration Stored on blob storage provides quick mount/unmount in other VM
72. SQL Azure Relational database as a service Highly available, automatically maintained Extension of the SQL Server Data Platform Business Analytics Reporting Data Sync Database There’s a driver for this: http://sqlsrvphp.codeplex.com
73. SQL Azure Relational database, provided as a service Highly symmetrical development and tooling experience (use TDS protocol and T-SQL) Highly scaled out, on commodity hardware Built on the SQL Server technology foundation Beyond “hosted database” High availability, DB provisioning, and DB management are provided by the service Pay for what you use
74. Windows Azure AppFabric Secure connections between services Across organizational boundaries Claims-based access control ServiceBus AccessControl There’s an SDK for this: http://dotnetservicesphp.codeplex.com/
76. Microsoft Codename “Dallas” Content brokerage and discovery platform Available as a CTP at commercial launch Microsoft Codename “Dallas”Information Services
77. Microsoft Codename “Sydney” - Connectivity WINDOWS AZURE PLATFORM ENTERPRISE Data Service Service Bus Access Control Service Code Name “Project Sydney”
78. North America Region Asia Pacific Region Europe Region N. Europe Sub-region N. Central – US Sub-region E. Asia Sub-region W. Europe Sub-region S. Central - US Sub-region S.E. Asia Sub-region
89. Using PHP with Windows Azure It’s all about… Running PHP Code in Windows Azure Eclipse Tooling Build, Test, Deploy PHP Projects Create New or Use Existing PHP Projects Scaling PHP Apps Using Cloud Storage from PHP Using Windows Azure Storage Using SQL Azure
90. Running PHP in Windows Azure How to Do It Host in Web role (like .NET) Supply PHP runtime Point to runtime via FastCGIconfiguration in Web.config Web.roleConfig Eclipse Tooling athttp://windowsazure4e.org does the above for you Command-line tools at http://azurephptools.codeplex.com PHP Web Role Instance 1 VIP Load Balancer PHP Web Role Instance 2
91. Developer tools Development Use your favourite editor Local debugging Windows with IIS 7.x Visual Studio Windows Azure tools for Eclipse Packaging Windows Azure SDK Deployment Any browser
92. PHP + Cloud Storage Windows Azure Storage On-Premise VIP PHP Web Role Load Balancer PHP App SQL Azure Windows Azure Platform
95. Windows Azure SDK for PHP A PHP programming model for Windows Azure Storage
96. PHP with Windows Azure Storage Windows Azure SDK for PHP at http://phpazure.codeplex.com PHP programming model for Windows Azure Storage Features PHP classes for Blobs, Tables & Queues Store PHP sessions in Table Storage File system wrapper for Blob Storage
97. Windows Azure SDK for PHP Overview Enables PHP developers to take advantage of the Microsoft Cloud Services Platform – Windows Azure. Open source project being contributed to Zend Framework (http://framework.zend.com) Features PHP classes for Windows Azure Blobs, Tables & Queues (for CRUD operations) Helper Classes for HTTP transport, AuhN/AuthZ, REST & Error Management Manageability, Instrumentation & Logging support Project site: http://phpazure.codeplex.com/ Logical architecture Your PHP application REST Compute Storage Manage Deployment scenarios PHP Runtime Any internet connected Server PHP Runtime REST REST
99. Windows Azure Blobs Unstructured data Scale massively At least 3 instances, 5 in optimal situation Can be used as CDN Can be mapped using a custom domain
100. Tools for connecting to blob storage CloudBerryLab Explorerhttp://www.cloudberrylab.com Azure Storage Explorerhttp://azurestorageexplorer.codeplex.com/ Onlinehttp://myazurestorage.com / ftp://ftp.cloudapp.net Windows Azure tooling for Eclipse
101. Blobs Sample $blobStorage= new Microsoft_WindowsAzure_Storage_Blob(); // Create if (!$blobStorage->containerExists($containerName)) { $blobStorage->createContainer($containerName); $blobStorage->setContainerAcl($containerName, Microsoft_WindowsAzure_Storage_Blob::ACL_PUBLIC); } // Store $blob = $blobStorage->putBlob($containerName, $blobName, $localFilename, $metadata); /* @var $blob Microsoft_WindowsAzure_Storage_BlobInstance */
103. Blob Stream Wrapper $blobStorage= new Microsoft_WindowsAzure_Storage_Blob(); // Register: $blobStorage->registerStreamWrapper(); // registers azure:// // or $blobStorage->registerStreamWrapper('blob://'); // use blob:// // Use $fp= fopen('azure://mycontainer/myfile.txt', 'r'); // ... fclose($fp);
104. Windows Azure Drive (a.k.a. Xdrive) Virtual NTFS volume that can be mounted .vhd format Use existing NTFS API’s Easier migration Stored on blob storage provides quick mount/unmount in other VM http://phpazurecontrib.codeplex.com
105. Queue Workflow Concepts Windows Azure Queue Provides Guarantee delivery (two-step consumption) Worker Dequeues Message and mark it as Invisible Worker Deletes Message when finished processing it If Worker role crashes, message becomes visible for another Worker to process Doesn’t guarantee “only once” delivery Doesn’t guarantee ordering Best effort FIFO Worker Role Web Role Input Queue (Work Items) Worker Role Azure Queue Web Role Worker Role Web Role Worker Role
106. Azure Queues RemoveMessage GetMessage (Timeout) Worker Role PutMessage Queue Msg 1 Msg 2 Msg 2 Msg 1 Web Role Worker Role Worker Role Msg 3 Msg 4 Msg 2
107. Loosely Coupled Work with Queues Worker-Queue Model Load work in a queue Many workers consume the queue Input Queue (Work Items) Azure Queue Worker Role Web Role Worker Role Web Role Worker Role Web Role Worker Role
108. Queues $queueClient= new Microsoft_WindowsAzure_Storage_Queue(); // Create $result = $queueClient->createQueue('imageQueue'); // Delete $queueClient->deleteQueue('imageQueue'); // Add message $queueClient->putMessage('imageQueue', $message, $ttl); // Retrieve Messages $messages = $queueClient->getMessages('imageQueue', 10); foreach($messages as $message) { // Do work here... $queueClient->deleteMessage('imageQueue', $message); }
109. Windows Azure Data Storage – Tables (Terms Part 1) Table Contains a set of entities. Entity (Row) Basic data items stored in a table. Property (Column) Single value in an entity. RowKey Unique ID of the entity within a partition Timestamp Time it was created
110. Windows Azure Data Storage – Tables (Terms Part 2) Partition Entities in a table with the same partition key PartitionKey Segments entities in to partitions to automatically distribute the table’s entities over many storage nodes. Sort Order There is a single index provided, where all entities in a table are sorted by PartitionKey and then RowKey
111. Key Example – Blog Posts Partition 1 Partition 2 Getting all of dunnry’s blog posts is fast Single partition Getting all posts after 2008-03-27 is slow Traverse all partitions
112. Table Sample $tableStorage= new Microsoft_WindowsAzure_Storage_Table( 'table.core.windows.net', 'myaccount', 'myauthkey'); // Create $result = $tableStorage->createTable($tableName); // List $result = $tableStorage->listTables(); foreach($result as $table) { echo 'Table name is: ' . $table->Name . ""; } // Delete $tableStorage->deleteTable($tableName);
113. Tables with Entities // Structured entity class ImageEntityextends Microsoft_WindowsAzure_Storage_TableEntity { /** * @azure filename */ public $filename; /** * @azure size Edm.Int64 */ public $size; } // Unstructured entity // Microsoft_WindowsAzure_Storage_DynamicTableEntity
128. Migrating schema and data SQL Azure Migration Wizardhttp://sqlazuremw.codeplex.com SQL Azure Data Sync Tool for SQL Serverhttp://www.microsoft.com/windowsazure/developers/sqlazure/datasync/ SQL Server Management Studio 2008 R2 November Community Technology Preview
129. PHP with SQL Azure SQL Server Driver for PHP at http://sqlsrvphp.codeplex.com/ Supports PHP access to SQL Azure Features Choose between SQL Server and SQL Azure by changing connection string Use from on-premise apps or in Windows Azure
130. PHP with AppFabric AppFabric SDK for PHP developers athttp://dotnetservicesphp.codeplex.com/ Supports PHP on service bus and access control Features Expose on-premise apps on an external endpoint without opening firewall Pub/sub scenario’s …
142. 3 simple steps… Get an account Get the tools Play, learn, develop, deploy
143. Get an account You need a Windows Live ID (WLID) Create one on https://signup.live.com Create an account on Microsoft Online Services Portal (MOCP) and buy Azure Subscription http://mocp.microsoftonline.com There is an Introductory Special (= Limited Amount at No Charge) Create your Azure Project https://windows.azure.com
151. Resources Windows Azurehttp://www.azure.com Windows Azure SDK for PHPhttp://phpazure.codeplex.com SQL Server Driver for PHPhttp://sqlsrvphp.codeplex.com AppFabric SDK for PHP developershttp://dotnetservicesphp.codeplex.com Command-line toolshttp://azurephptools.codeplex.com PDChttp://microsoftpdc.com PHP Architect December 2009 issuehttp://www.phparch.com Windows Azure Companionhttp://code.msdn.microsoft.com/azurecompanion InteroperabilityBridges.comhttp://interoperabilitybridges.com Web Platform Installerhttp://microsoft.com/web My bloghttp://blog.maartenballiauw.be/category/Azure.aspx RealDolmen blogs is running on Azure!http://www.realdolmenblogs.com
154. Thankyou … … foryourattention ! … for fillingout f Maarten Balliauwhttp://blog.maartenballiauw.be http://bit.ly/aQuc56
Editor's Notes
CREATE TABLE [dbo].[posts]( [Id] [numeric](18, 0) IDENTITY(1,1) NOT NULL, [Slug] [nvarchar](255) NOT NULL, [Title] [nvarchar](255) NOT NULL, [Body] [text] NOT NULL, [Author] [nvarchar](255) NOT NULL, [PubDate] [datetime] NOT NULL, CONSTRAINT [PK_posts] PRIMARY KEY CLUSTERED ( [Id] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
In a classic IT model, there are a lot of inefficiencies.Barrier for innovationsFor every solution to be deployed, an investment needs to be done. For example, 2 servers are bought and configured by corporate IT.These investments are repeated: whenever capacity is estimated too low, a new investment is done. For example, 2 extra servers are bought and configured by corporate IT every quarter.Waste of capacitiesAt a given moment, we have 4 servers. But the actual load could have been handled with only 1. This means we invested 400% too much!Under-supply of capacitiesAt a given moment, we get some press coverage and the actual load increases more than estimated. Imagine we have 1 server short. This may be no problem, but if our checkout process is running on this machine, we have the # of users that can be handled by 1 server that can not make a purchase. Which means we lose a lot of possible income!Fixed-cost of IT-capacitiesWhen the load drops for a period in time, and only 1 server is actually required, we still have to maintain and support all the other servers. This comes at a cost, that should not be made at this time: we are not using it!In a cloud model, the actual capacity can be kept closer to the actual load, with less over-capacity. No investment needs to be done: only pay a small amount at th start, pay more when your solution is used more. Whenever over-capacity exists, scale the solution down to less resources and see immediate impact on costs.IT is no longer treated as an investment, rather as a cost. We don’t invest in power generators, rather pay our electricity by use. This paradigm can become true for IT by using a cloud model.IT can become a business enabler!Ideas can be tried without a large investment upfront, reducing risks and costs. Imagine an application try-out in an insurance company that wants to test if a cost simulation on their site is used and attracts customers & revenue. In a classic IT model, an investment should be made. In a cloud model, we are having a fraction of the costs for trying this out. If it succeeds and attracts revenue, we can easily cope with higher usage costs. If the simulation tool does not attract revenue, we can take it down and our cost disappears, without having invested upfront.Cloud computing, in short, means capacity / resources in terms of networking, data, storage or compute power are provided in an on-demand model: go to a portal and resources are there fast. This is unlike traditional IT where a whole process should be followed. Being agile means you can respond to the market faster!Economics are different: there’s a pay-per-use model, upfront investments are no longer needed.Cloud != virtualization like a lot of vendors tell! Cloud is an addition to virtualization: it allows you to transparently scale the demand in resources across virtual machines, without having to know on which machine you are working. This increases usage and effectiveness of virtualization.Cloud services have inherent resilience to hardware or software failures due to redundant/self-healing service models combined with deep integration between ops & development/test providing a lights out experience. Cloud is the future: most vendors are projecting a future image of devices (PC’s, mobiles, TV’s, …), interconnected through the Internet and using hosted services. To achieve best cost-effectiveness, these hosted services are in a cloud, whether a public cloud or a private cloud.Cloud computing will drive competition in the future due to cost-efficiency.
Datacenter pairing!
Take your application to the next level
http://eric.blob.core.windows.net/music/rock/rush/xanadu.mp3Blobs – Provide a simple interface for storing named files along with metadata for the fileTables – Provide structured storage. A Table is a set of entities, which contain a set of propertiesQueues – Provide reliable storage and delivery of messages for an applicationTab
Harvesting!
Use queues as a way of communicating w/ the backend worker rolesWRs call getmessage and pass timeoutTimeout value is importantExpiration time is important; message is marked in the queue as invisible; for duration of timeout it’s invisibleWhen we’re done processing, we call a message to remove the message through a deleteTh reason we do this is imagine we have a second worker role; if something goes wrong, once the timeout expires, the message becomes visible, and the next person to do a get message will get the message
The PartitionKey combined with the RowKey uniquely identifies an entity in a table.
11:53Getting the all of dunnry’s post it fast because we’re selecting the entities by a partition keyGetting all of the posts after a certain is slow because we may have to traverse across multiple servers because we’re selecting entities that span partition keysA query without the partition key is really a scan
We have included this feature comparison table in anticipation of your likely questions about differences between using a relational database table as you may be currently doing with your SQL Server databases and the new Windows Azure Tables included in Windows Azure.
As I stated earlier, SQL Azure is based on SQL Server 2008. At this time it is only a subset of the features of the server product.My intention here is to convey the high level features that are supported and the ones that are not.SQL Azure will support most of the things we need… Tables, Index, Views, Stored Procedures, Triggers, and Constraints… in my book… that’s all the functionality that I need for most of my applications.There are some other adjunct technologies that ship as part of SQL Server 2008 such as SQL Reporting Services and Analysis Services which are not supported. The Service Broker is also not supported.
So let’s assume that we have designed our relational database with local developer and data modeling tools.We can begin our story then by assuming that we want to get our database deployed to the cloud.There are some tools that will expedite this process which I will show you later, but for now lets assume that we have scripted our database schema. We apply this script to SQL Azure which speaks native TDS.If you created your database through the SQL Azure Portal, then SQL Azure will have created one master database and three replicas of that database. If you create your database with the script the same will be true.These replicas are stored in different database centers from the master to provide redundancy and protection against geographical catastrophe.
Configuring our application to use SQL Azure storage instead of SQL Server is simply a matter of modifying the connection string in our application’s configuration file.When our application requests data, ADO.NET speaks to the TDS which directs our queries to the master database server. The master database server performs our query and returns the results to our application.
From our application’s point of view, there is only one SQL Azure database.As we make updates to our database, those updates are replicated to other copies stored in other data centers so that in the event that our database fails for any reason, the other databases will be standing by ready to take its place.
But what if that master database server fails for some reason?TDS is receives notification of the database failure and automatically redirects the call to the replica!The Azure Cloud Fabric is self-healing… and the details are outside the scope of this presentation; however, the fabric will get busy repairing itself like drones on a Borg mother ship… essentially with the objective of keeping three replicas online at a time.
I will demonstrate creating a SQL Azure account in session 3 where I will walk you through the entire process.For now I simply want to give you some background information to prepare you for our first demonstration.When we create our SQL Azure database server, we’ll be prompted for an Administrator’s name and a password.This username and password will be the granted a system administrator role that is similar to the “sa” account on a local SQL Server 2008 box. The account has permission to create and drop databases and database ownership authority in any databases that you create with this account.
After creating your SQL Azure database server, you will want to grant appropriate access through the SQL Azure firewall.SQL Azure provides a very simple and easy to maintain firewall. The firewall is so easy to use that it’s only going to get one slide in my deck!The firewall allows us to expose our database to Windows Azure services via a checkbox and to add ranges of IP addresses such as your home office and your business… or possibly the address of a 3rd party server hosting some application that needs data access.I’ll do a thorough demo of this feature in session 3…
When you created your SQL Azure database server, you supplied an administrator’s user name and password. I have named my user accordingly… to remind me of its power.The SQL Portal will offer you the ability to copy these credentials in connection string format to your clip board… tempting you into believing that you should just paste this into your configuration file.This is terrific for demos like mine… BUT you should NEVER, EVER do this…A database server system administrator password placed in a configuration file in clear text format… there has got to be something naive in the extreme going on here… and worse… no way to create non-sa-like users through the UI… you must script your database users and then apply the script to the database. And to anticipate your question… no… you can’t use SQL Server Management Studio to do this either.I will demo this as well in session 3… so hang tight…
Vragen: zijn er managers aanwezig?
THOMAS: We should not include a Q&A in the track session, refer to the “Meet the experts” setup for people with questions. Only allowed if running too fast.