KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Launch external PHP interpreter from 4D
PRODUCT: 4D | VERSION: 12 | PLATFORM: Mac & Win
Published On: November 12, 2010

When using an external PHP interpreter, it could be useful to automate the starting of the interpreter. Typically, the external PHP application is started by running a command in the Command Prompt or Terminal, which means that we can easily use the LAUNCH EXTERNAL PROCESS command to start it automatically.

Here is a short method that shows an example of how to start an external PHP interpreter:

C_TEXT($command_t)
C_LONGINT($platform_l)

PLATFORM PROPERTIES($platform_l)
If ($platform_l=Windows)
    $command_t:="c:\\Program Files (x86)\\PHP\\php-cgi.exe -b 127.0.0.1:9002"
Else
    $command_t:="/opt/local/bin/php-cgi -b 127.0.0.1:9002"
End if

SET ENVIRONMENT VARIABLE("_4D_OPTION_BLOCKING_EXTERNAL_PROCESS";"false")
LAUNCH EXTERNAL PROCESS($command_t)


This code would most likely be added to the startup code for a database.

The commands specified are simply the commands that we use to start the interpreter from the Command Prompt or Terminal. One other thing to note is the SET ENVIRONMENT VARIABLE command. We want the php-cgi application to run continuously and it is not going to respond back to 4D, so we need to run it asynchronously. The SET ENVIRONMENT VARIABLE command as it is used above, will allow 4D to continue working, even though the php-cgi application is not responding back to 4D (see the following Tech Tip for more details: https://kb.4d.com/search/assetid=75815)