VB6 - Integrate PHP into your webserver with a single function.
So you've built a webserver and the question remains:
How do I add PHP functionality to it?
To tackle this problem first you need to understand the core working of PHP.
PHP isn't a server application on itself, it's just a processing application, intended as a server plug-in.
Servers applications only have the task of interpreting the requests and sending a response back.
So if you put a PHP-file in php.exe it processes the file and gives plain HTML as output. And the server application sends it as a response to the request.
Knowing this it's just finding a way of capturing the output and selecting the correct parameters.
Puzzling around I've built the following function which will allow you to set the parameters and capture the output of php.exe.
Code:
Public Function ProcessPHP(ByVal FilePath As String, Optional ByVal phpPath As String = "C:\XAMPP\php\php-win.exe", Optional ByVal Args As String = "-f") As String
'Using reference to: Windows Script Host Object Model
' "System32\wshom.ocx"
'/// Declare Shell Objects
Dim Shell As New WshShell
Dim retObj As WshExec
Dim retStr As TextStream
'/// Declare Basic Variables
Dim cCommand As String
Dim q As String
'/// q is for quoting the filepath correctly in the command
q = """"
'/// Put together the command
cCommand = phpPath & " " & Args & " " & q & FilePath & q
'/// Execute command
Set retObj = Shell.Exec(cCommand)
'/// Put return value in textstream and make a string value out of it
Set retStr = retObj.StdOut
ProcessPHP = retStr.ReadAll
End Function
Usages as follows:
Code:
[ResponseHTML] = ProcessPHP([PHP file path], [php-win.exe location])
Don't forget to set reference to the "Windows Script Host Object Model".
TheBigB.