4D v14.3Executing PHP scripts in 4D |
||
|
4D v14.3
Executing PHP scripts in 4D
Executing PHP scripts in 4D
4D lets you directly execute PHP scripts. This new possibility gives you access to the wealth of utility libraries available via PHP. More particularly, these libraries provide the following functions:
This list is not exhaustive. For a complete list of the PHP modules available by default with 4D, please refer to the [#title id="2802"/] section. Also, please note that it is possible to install additional custom modules. To execute a PHP script or function, you must use the PHP Execute command. By default, 4D includes version 5.4.11 of PHP. Executed scripts must be compatible with this version and with the modules installed. For a complete description of PHP commands and syntax, please refer to the abundant PHP documentation available on the Internet. As an example, here are the addresses for a few reference sites: 4D provides a PHP interpreter compiled in FastCGI, client-server type communication protocol between an application and a PHP interpreter. The PHP interpreter pilots a set of system execution processes called "child processes". These processes are dedicated to the processing of requests sent by 4D. The execution of the requests is synchronous. For optimization reasons, by default up to five child processes can be run simultaneously (this number can be modified via the Database Settings or via the SET DATABASE PARAMETER command). Under Mac OS, these processes launched on the first request and are kept permanently by the PHP interpreter. Under Windows, 4D creates the processes according to its needs and recycles them if necessary. 4D automatically supports the handling of the processes of the PHP interpreter provided by default (launching and closing). Note: If the 4D program quits unexpectedly while child PHP processes are still active, you must delete them manually via the system process management window. The following diagram illustrates the 4D/PHP architecture of 4D: This architecture works with a system of internal requests sent by 4D to a predefined TCP address (IP address and port number). If necessary, for example if several PHP interpreters are executed on the same machine, this address can be modified via the Database Settings or via the SET DATABASE PARAMETER command. Warning: If you launch two 4D applications on the same machine and execute PHP statements on each of them (via the PHP Execute command), it is imperative to modify the listening ports of the FastCGI PHP interpreter so that you use a different one for each application. Otherwise, PHP statements may fail to execute correctly in an unpredictable manner and even freeze your 4D application. You can choose to use another PHP interpreter than the one provided by 4D. This allows you to keep the same PHP interpreter even if 4D is updated. In addition, it allows you to install all the custom modules you want -- in fact, you cannot use a custom PHP file with the interpreter included in 4D. To use PHP configuration options other than the ones provided by default, you need to manage an external interpreter. A custom PHP interpreter must respect two conditions:
To use a custom PHP interpreter, you simply need to configure it so that it listens to a specific address and TCP port and to indicate to 4D to not activate the internal interpreter. These parameters can be specified either via database settings, or for the session via the SET DATABASE PARAMETER command. Of course, in this case, you must manage the starting and functioning of the interpreter yourself. The php.ini initialization file is placed in the Resources folder of the database. The php.ini file can be used, more particularly, to declare the location of the PHP extensions. The php.ini file of the external interpreter must contain the following entries:
|
PROPERTIES
Product: 4D SEE ALSO ARTICLE USAGE
4D Language Reference ( 4D v14 R2) Inherited from : Executing PHP scripts in 4D ( 4D v12.4) |