Commit: be31b985b0c93375abff9cc2450243d7ff671620
Author: Stephen Zarkos <stephen.zar...@microsoft.com> Wed, 21 Nov
2012 15:29:19 -0800
Parents: 57566b454dd6ffd88f8c8d45541e8c3ed51a850f
Branches: master
Link:
http://git.php.net/?p=web/rmtools.git;a=commitdiff;h=be31b985b0c93375abff9cc2450243d7ff671620
Log:
Add PGO scripts
Changed paths:
A pgo-build/pgo_controller.ps1
A pgo-build/setup-utils.ps1
A pgo-build/unzip.php
diff --git a/pgo-build/pgo_controller.ps1 b/pgo-build/pgo_controller.ps1
new file mode 100644
index 0000000..490cda8
--- /dev/null
+++ b/pgo-build/pgo_controller.ps1
@@ -0,0 +1,155 @@
+#%powershell1.0%
+#
+# File: pgo_controller.ps1
+# Description:
+# - Deploy PGI build on remote server
+# - Set up IIS and Apache with PGI builds of PHP
+# - Run training scripts to collect profiling data
+# - Collect .pgc files
+#
+## Example: pgo_controller.ps1 -PHPBUILD
C:\obj\ts-windows-vc9-x86\Release_TS\php-5.4.0RC6-dev-Win32-VC9-x86.zip -PHPVER
php-5.4
+
+Param( $PHPBUILD="", $PHPVER="" )
+if ( ($PHPBUILD -eq "") -or ($PHPVER -eq "") ) {
+ write-output "Usage: pgo_controller.ps1 -PHPBUILD <path_to_.zip>
-PHPVER <php_ver>"
+ exit
+}
+
+$SERVER = "php-pgo01"
+$WebSvrPHPLoc = "\\$SERVER\pgo"
+$WebSvrApacheLoc = "\\$SERVER\Apache2"
+$RemoteBaseDir = "C:\pgo"
+$RemotePHPBin = "C:\pgo\php-nts-bin\php.exe"
+
+$BaseDir = "c:\php-sdk\pgo-build"
+$LocalPHPBin = "C:\php-sdk\php\php.exe"
+$BaseBuildDir = "c:\php-sdk"
+$ObjDir = "$PHPBUILD\..\obj"
+
+## Import needed functions
+Set-Location $BaseDir
+. .\setup-utils.ps1
+
+## Simple logging function.
+Function logger ( $msg ) {
+ $logfile = "$BaseDir\log.txt"
+ $msg = (get-date -format "yyyy-MM-dd HH:mm:ss")+" $msg"
+ $msg | Out-File -Encoding ASCII -Append $logfile
+}
+
+###################################################################################
+## Setup PHP and run the profiling tools.
+##
+
+$build = ""
+$PHPBUILD = $PHPBUILD -replace '/', '\'
+$build = $PHPBUILD.split('\')
+$build = [string]$build[($build.length-1)]
+$build = $build -ireplace "\.zip", ""
+
+$trans = invoke-expression -command "$LocalPHPBin
$WebSvrPHPLoc\scripts\pgo.php printnum"
+$trans = [string]$trans
+$trans = $trans.split(':')
+$trans = $trans[$trans.length-1].trim()
+
+$exts = $build.split('-')
+$exts = 'pecl-'+$exts[1]
+$exts = ($PHPBUILD -replace '\\php\-\d.+$', '') + '\' + $exts
+
+## Locking here.
+$lockfile = 'php-ts'
+if ( $PHPBUILD -match "nts" ) {
+ $lockfile = 'php-nts'
+}
+if ((set-lock $lockfile) -eq $false ) {
+ logger "PGO Controller: set-lock($lockfile) returned error."
+ write-output "PGO Controller: set-lock($lockfile) returned error."
+ exit
+}
+
+## Stop relevant web services on the server
+logger "PGO Controller: Starting PHP configuration."
+if ( $PHPBUILD -match "nts" ) {
+ $( winrs -r:$SERVER net stop w3svc )
+}
+else {
+ $( winrs -r:$SERVER net stop Apache2.2 )
+}
+
+## Copy and set up PHP runtime.
+if ( (setup-php $exts $PHPBUILD) -eq $false ) {
+ logger "PGO Controller: setup-php() returned error."
+ write-output "PGO Controller: setup-php() returned error."
+ remove-lock $lockfile
+ exit
+}
+
+## Set up IIS or Apache
+if ( $PHPBUILD -match "nts" ) {
+ if ( (setup-iis $build $trans) -eq $false ) {
+ logger "PGO Controller: setup-iis() returned error."
+ write-output "PGO Controller: setup-iis() returned error."
+ remove-lock $lockfile
+ exit
+ }
+}
+else {
+ if ( (setup-apache($build)) -eq $false ) {
+ logger "PGO Controller: setup-apache() returned error."
+ write-output "PGO Controller: setup-apache() returned error."
+ remove-lock $lockfile
+ exit
+ }
+}
+
+if ( $PHPBUILD -match "nts" ) {
+ $phpini = "$BaseDir/ini/$PHPVER-pgo-nts.ini"
+ if ( (php-configure $build $phpini) -eq $false ) {
+ logger "PGP Controller: php-configure() returned error: $build,
$phpini"
+ remove-lock $lockfile
+ exit
+ }
+ $( winrs -r:$SERVER net stop w3svc "&" net start w3svc )
+ $( winrs -r:$SERVER C:/windows/system32/inetsrv/appcmd stop site
/site.name:"Default Web Site" )
+ $( winrs -r:$SERVER C:/windows/system32/inetsrv/appcmd start site
/site.name:"drupal" )
+ $( winrs -r:$SERVER C:/windows/system32/inetsrv/appcmd start site
/site.name:"joomla" )
+ $( winrs -r:$SERVER C:/windows/system32/inetsrv/appcmd start site
/site.name:"mediawiki" )
+ $( winrs -r:$SERVER C:/windows/system32/inetsrv/appcmd start site
/site.name:"phpbb" )
+ $( winrs -r:$SERVER C:/windows/system32/inetsrv/appcmd start site
/site.name:"wordpress" )
+ $( winrs -r:$SERVER C:/windows/system32/inetsrv/appcmd start site
/site.name:"symfony" )
+ $( winrs -r:$SERVER powershell C:\pgo\scripts\pgo-iis.ps1 -PHPBUILD
$build )
+}
+else {
+ $phpini = "$BaseDir/ini/$PHPVER-pgo-ts.ini"
+ if ( (test-path "$exts\php_apc.dll") -eq $true ) {
+ $phpini = "$BaseDir/ini/$PHPVER-pgo-ts-apc.ini"
+ }
+ if ( (php-configure $build $phpini) -eq $false ) {
+ logger "PGO Controller: php-configure() returned error: $build,
$phpini"
+ remove-lock $lockfile
+ exit
+ }
+ $( winrs -r:$SERVER net stop Apache2.2 "&" net start Apache2.2 )
+ $( winrs -r:$SERVER $RemotePHPBin C:\pgo\scripts\pgo.php localhost 8080
)
+}
+
+if ( $PHPBUILD -match "nts" ) {
+ $( winrs -r:$SERVER net stop w3svc )
+}
+else {
+ $( winrs -r:$SERVER net stop Apache2.2 )
+}
+
+## Important - need to give instrumentation time to
+## create .pgc files after stopping the server.
+Start-Sleep -s 10
+
+## Collect the .pgc files
+$LocalBuildDir = $PHPBUILD -replace "$build\.zip", ''
+remove-item "$LocalBuildDir/*.pgc" -force
+copy-item -force "$WebSvrPHPLoc/$build/*.pgc" -destination $LocalBuildDir
+copy-item -force "$WebSvrPHPLoc/$build/ext/*.pgc" -destination $LocalBuildDir
+
+## Remove lock
+remove-lock $lockfile
+
diff --git a/pgo-build/setup-utils.ps1 b/pgo-build/setup-utils.ps1
new file mode 100644
index 0000000..492071a
--- /dev/null
+++ b/pgo-build/setup-utils.ps1
@@ -0,0 +1,148 @@
+#%powershell1.0%
+#
+# File: setup-utils.ps1
+# Description: Utility functions for configuring PHP, IIS and Apache
+#
+
+#
+## Description: Check and set the lock file on the PGO host.
+#
+Function set-lock ( $lockfile ) {
+ for ($i=0; $i -lt 70; $i++) {
+ if ( (test-path "$WebSvrPHPLoc\$lockfile") -eq $true ) {
+ logger "set-lock($lockfile): $WebSvrPHPLoc\$lockfile
exists, waiting for 60 seconds."
+ Start-Sleep -s 60
+ }
+ else {
+ try {
+ logger "set-lock($lockfile): Creating lockfile
$WebSvrPHPLoc\$lockfile."
+ new-item -path $WebSvrPHPLoc -name $lockfile
-type file -ErrorAction stop | out-null
+ return $true
+ }
+ catch {
+ logger "set-lock($lockfile): Error creating
$WebSvrPHPLoc\$lockfile, $_."
+ write-output "set-lock($lockfile): Error
creating $WebSvrPHPLoc\$lockfile, $_."
+ return $false
+ }
+ }
+ }
+
+ return $false
+}
+
+Function remove-lock ( $lockfile ) {
+ logger "remove-lock($lockfile): removing lockfile
$WebSvrPHPLoc\$lockfile."
+ remove-item -path "$WebSvrPHPLoc\$lockfile" -Force
+ if ( (test-path "$WebSvrPHPLoc\$lockfile") -eq $true ) {
+ logger "remove-lock($lockfile): lockfile
$WebSvrPHPLoc\$lockfile not removed."
+ }
+}
+
+
+#
+## Description: Unzip the PHP download onto the webserver
+#
+Function setup-php ( $extdir="", $phploc ) {
+
+ logger "setup-php(): Setting up PHP with exts=$extdir and php=$phploc"
+
+ ## Unzip the PHP files
+ $phploc = $phploc -replace '/', '\'
+ $phpdir = $phploc.split('\')
+ $phpdir = [string]$phpdir[($phpdir.length-1)]
+ $phpdir = $phpdir -ireplace "\.zip", ""
+
+ if ( (test-path "$WebSvrPHPLoc\$phpdir") -eq $true ) {
+ logger "setup-php(): The directory $WebSvrPHPLoc\$phpdir
exists, removing."
+ remove-item "$WebSvrPHPLoc\$phpdir" -Recurse -Force | out-null
+ }
+
+ logger "setup-php(): Unzipping $phploc into $WebSvrPHPLoc\$phpdir"
+ new-item -path $WebSvrPHPLoc -name $phpdir -type directory -Force |
out-null
+
+## This method apparently does not work when called as a background process.
+# $shell = new-object -com shell.application
+# $zipsource = $shell.namespace( "$phploc" )
+# $destination = $shell.namespace( "$WebSvrPHPLoc\$phpdir" )
+# $destination.Copyhere( $zipsource.items(), 20 )
+ $out = & $LocalPHPBin "$BaseDir\unzip.php" "$phploc"
"$WebSvrPHPLoc\$phpdir"
+ if ( $LastExitCode -ne 0 -or (test-path
"$WebSvrPHPLoc\$phpdir\php-cgi.exe") -eq $false ) {
+ logger "setup-php(): Error, $WebSvrPHPLoc\$phpdir\php-cgi.exe
does not exist."
+ return $false
+ }
+
+# copy-item -Force "$extdir\*" -destination "$WebSvrPHPLoc\$phpdir\ext\"
-recurse ## PECL support
+}
+
+
+#
+## Description: Configure PHP for Apache.
+#
+Function setup-apache( $phppath="" ) {
+ if ( $phppath -eq "" ) {
+ return $false
+ }
+ logger "setup-apache(): Setting up Apache using PHP=$phppath"
+
+ $phpdir = $RemoteBaseDir -replace '\\', '/'
+
+ $conffile = "$WebSvrApacheLoc/conf/extra/httpd-php.conf"
+ $config = "LoadModule php5_module
`"$phpdir/$phppath/php5apache2_2.dll`"`n"
+ $config += "AddType application/x-httpd-php .php`n"
+ $config += "PHPIniDir `"$phpdir/$phppath`"`n"
+
+ $config | Out-File -encoding ASCII $conffile
+ if ( (test-path $conffile) -eq $false ) {
+ return $false
+ }
+}
+
+
+#
+## Description: Configure PHP for IIS.
+#
+Function setup-iis( $phppath="", $trans=0 ) {
+ logger "setup-iis(): Setting up IIS with PHP=$phppath,
Transactions=$trans"
+ if ( ($phppath -eq "") -or ($trans -eq "") ) {
+ return $false
+ }
+
+ ## Clear any current PHP handlers
+ $( winrs -r:$SERVER "%windir%\system32\inetsrv\appcmd clear config
/section:system.webServer/fastCGI" )
+ $( winrs -r:$SERVER "%windir%\system32\inetsrv\appcmd set config
/section:system.webServer/handlers /-[name='PHP_via_FastCGI']" )
+
+ ## Set up the PHP handler
+ $( winrs -r:$SERVER "%windir%\system32\inetsrv\appcmd set config
/section:system.webServer/fastCGI
/+[fullPath=`'$RemoteBaseDir\$phppath\php-cgi.exe`']" )
+ $( winrs -r:$SERVER "%windir%\system32\inetsrv\appcmd set config
/section:system.webServer/handlers
/+[name='PHP_via_FastCGI',path='*.php',verb='*',modules='FastCgiModule',scriptProcessor=`'$RemoteBaseDir\$phppath\php-cgi.exe`',resourceType='Unspecified']"
)
+ $( winrs -r:$SERVER "%windir%\system32\inetsrv\appcmd set config
/section:system.webServer/handlers /accessPolicy:Read,Script" )
+
+ ## Configure FastCGI variables
+ $( winrs -r:$SERVER "%windir%\system32\inetsrv\appcmd set config
-section:system.webServer/fastCgi
/[fullPath=`'$RemoteBaseDir\$phppath\php-cgi.exe`'].instanceMaxRequests:10000" )
+ $( winrs -r:$SERVER "%windir%\system32\inetsrv\appcmd set config
-section:system.webServer/fastCgi
/[fullPath=`'$RemoteBaseDir\$phppath\php-cgi.exe`'].MaxInstances:1" )
+ $( winrs -r:$SERVER "%windir%\system32\inetsrv\appcmd.exe set config
-section:system.webServer/fastCgi
/+`"[fullPath=`'$RemoteBaseDir\$phppath\php-cgi.exe`'].environmentVariables.[name='PHP_FCGI_MAX_REQUESTS',value=`'$trans`']`""
)
+ $( winrs -r:$SERVER "%windir%\system32\inetsrv\appcmd.exe set config
-section:system.webServer/fastCgi
/+`"[fullPath=`'$RemoteBaseDir\$phppath\php-cgi.exe`'].environmentVariables.[name='PHPRC',value=`'$RemoteBaseDir\$phppath\php.ini`']`""
)
+}
+
+
+#
+## Description: Copy a php.ini onto the webserver.
+#
+function php-configure( $phppath="", $phpini="" ) {
+ if ( ($phppath -eq "") -or ($phpini -eq "") ) {
+ return $false
+ }
+ logger "php-configure(): Configuring PHP with PHP=$phppath and
INI=$phpini"
+ copy-item "$phpini" -destination "$WebSvrPHPLoc/$phppath/php.ini"
+
+ $phpdir = $RemoteBaseDir -replace '\\', '/'
+ if ( $phppath -ne "nts" ) {
+ $contents = (get-content "$WebSvrPHPLoc/$phppath/php.ini")
+ out-file -encoding ASCII -Force "$WebSvrPHPLoc/$phppath/php.ini"
+ Foreach ( $line in $contents ) {
+ if ( $line -match "^extension_dir" ) {
+ $line = "extension_dir =
`"$phpdir/$phppath/ext`""
+ }
+ $line | out-file -encoding ASCII -append
"$WebSvrPHPLoc/$phppath/php.ini"
+ }
+ }
+}
diff --git a/pgo-build/unzip.php b/pgo-build/unzip.php
new file mode 100644
index 0000000..3bcfbb8
--- /dev/null
+++ b/pgo-build/unzip.php
@@ -0,0 +1,18 @@
+<?php
+
+$zipfile = "$argv[1]";
+$destination = "$argv[2]";
+if ( !file_exists("$zipfile") || !file_exists("$destination") ) {
+ print "Usage: unzip.php <zip_file> <destination>\n";
+ exit(1);
+}
+
+$zip = new ZipArchive;
+if ( $zip->open("$zipfile") === TRUE ) {
+ $zip->extractTo( $destination );
+ $zip->close();
+}
+else {
+ exit(1);
+}
+?>
\ No newline at end of file
--
PHP Webmaster List Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php