search
Categories
Sponsors
VirtualMetric Hyper-V Monitoring, Hyper-V Reporting
Archive
Blogroll

Badges
MCSE
Community

Cozumpark Bilisim Portali
Executing PHP files on PowerShell
Posted in Windows Powershell | No Comment | 2,705 views | 14/07/2012 21:39

I’ve recently added PHP support on PoSHServer. Here is my example codes for PHP execution on PowerShell:

Main:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$PHPCgiPath = "C:\Program Files (x86)\PHP\v5.3\php-cgi.exe" # WebPI Location
$TestPHPCgiPath = Test-Path $PHPCgiPath
if ($TestPHPCgiPath)
{
	$Response.ContentType = "text/html"
	$PHPQuery = Get-PoSHPHPQuery -Request $Request
	$PHPContentOutput = Get-PoSHPHPContent -File $File -QueryString $PHPQuery -PHPCgiPath $PHPCgiPath
	$PHPContentOutput = Set-PHPEncoding -PHPOutput $PHPContentOutput
	$Response.StatusCode = [System.Net.HttpStatusCode]::OK
	$LogResponseStatus = $Response.StatusCode
	$Response = New-Object IO.StreamWriter($Response.OutputStream,[Text.Encoding]::UTF8)
	$Response.WriteLine("$PHPContentOutput")
}
else
{
	$Response.ContentType = "text/html"
	$Response.StatusCode = [System.Net.HttpStatusCode]::NotFound
	$LogResponseStatus = $Response.StatusCode
	$Response = New-Object IO.StreamWriter($Response.OutputStream,[Text.Encoding]::UTF8)
	$Response.WriteLine("$(. $PoSHModulePath\modules\phpcgierror.ps1)")						
}

Function:

1
2
3
4
5
6
7
function Get-PoSHPHPContent
{
param ($File, $QueryString, $PHPCgiPath)
 
	$PHPOutput = &$PHPCgiPath -f $File $QueryString
	$PHPOutput
}

You can always download PoSHServer to see it live! :)



Leave a Reply