Classes to use external PHP interpreter in execute, interactive or CGI mode.
The internal PHP Interpreter has been removed in v20 R31. Now it is "strongly advised" to use 4D.SystemWoker
to execute PHP code.
To effectively replace the CGI-based PHP Execute
2 with 4D.SystemWoker
3 you need to be able to do 3 things:
- Launch
php
once and keep it running - Talk to the interpreter through
stdIn
and hear back from it throughstdOut
andstdErr
- Terminate the running
php
when you no longer need it
For 1. and 3. you need to keep track of the single instance of 4D.SystemWoker
that is bound to the PHP interpreter.
For 2. you need to implement a controller object and run your code in an execution context of a dialog or a worker. Ideally the controller would be a generic class that can be easily extended according to specific needs.
This project shares a set of classes to execute PHP from 4D by using an external interpeter and CGI (the PHP Execute
command), interactive mode, or one-shot execute mode.
Get PHP from the offical site for Windows4 or from my repository5 for macOS. Alternatively, compile PHP from source. Place php
and/or php-cgi
at the following path:
/RESOURCES/bin/{platform}/
$ini:=File("/RESOURCES/php/php.ini")
$PHP:=cs.PHP.new(cs._PHP_Controller; $ini)
$PHP.run($input)
//the data is returned synchronously
$stdOut:=$PHP.data
$ini:=File("/RESOURCES/php/php.ini")
$PHP:=cs.PHP.new(cs._PHP_Controller; $ini)
$PHP.interactive()
//you can now post messages and receive data asynchronously
$PHP.controller.worker.postMessage($input+"\r\n")
$ini:=File("/RESOURCES/php/php.ini")
$CGI:=cs.PHP_CGI.new(cs._PHP_CGI_Controller; $ini).cgi()
//you can now use PHP Execute