4D v16.3PHP Execute |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v16.3
PHP Execute
PHP Execute
The PHP Execute command can be used to execute a PHP script or function. Pass the pathname of the PHP script to be executed in the scriptPath parameter. This can be a relative pathname if the file is located next to the database structure or an absolute path. The pathname can be expressed in either the system syntax or POSIX syntax. Pass a PHP function name in the functionName parameter if you want to execute a specific function in the scriptPath script. If you pass an empty string or omit the functionName parameter, the script is entirely executed. Note: PHP is case sensitive for function names. Do not use parentheses, just enter the function name only. The phpResult parameter receives the result of the execution of the PHP function. You can pass either:
The phpResult parameter can be of the Text, Longint, Real, Boolean, or Date type as well as (except for arrays) a field of the BLOB or Time type. 4D will carry out the conversion of the data and any adjustments needed according to the principles described in the Conversion of data returned section below.
If you call a PHP function that expects arguments, use the param1...N parameters to pass one or more values. The values must be separated by semi-colons. You can pass values of the Alpha, Text, Boolean, Real, Integer, Longint, Date or Time type. Pictures, BLOBs and Objects are not accepted. You can send an array; in this case, you must pass a pointer to the array to the PHP Execute command, otherwise the current index of the array will be sent as an integer (see the example). The command accepts all types of arrays except for pointer, picture and 2D arrays. Note: For technical reasons, the size of parameters passed via the FastCGI protocol must not exceed 64 KB. You need to take this limitation into account if you use parameters of the Text type. The command returns True if the execution has been carried out correctly on the 4D side, in other words, if the launching of the execution environment, the opening of the script and the establishing of the communication with the PHP interpreter were successful. Otherwise, an error is generated, which you can intercept with the ON ERR CALL command and analyze with GET LAST ERROR STACK. Note: PHP can be used to configure error management. For more information, please refer, for example, to the following page: http://www.php.net/manual/en/errorfunc.configuration.php#ini.error-reporting. The following table specifies how 4D interprets and converts data that is returned according to the type of the phpResult parameter.
(*) By default, HTTP headers are not returned: Note: If you need to recover large volumes of data using PHP, it is usually more efficient to pass by the stdOut buffer (echo command or similar) rather than by the function return. For more information, refer to the description of the PHP GET FULL RESPONSE command. You can use the SET ENVIRONMENT VARIABLE command to specify the environment variables used by the script. Warning: after calling LAUNCH EXTERNAL PROCESS or PHP Execute, the set of environment variables is erased. 4D provides the following special functions:
Note that the interpreter is relaunched automatically when the first request is sent by PHP Execute. Calling the "myPhpFile.php" script without any function. Here are the contents of the script: <?php The following 4D code: C_TEXT($result) ... will display "Current PHP version: 5.3" Calling the myPhpFunction function in the "myNewScript.php" script with parameters. Here are the contents of the script: <?php Calling with function: C_TEXT($result) Quitting the PHP interpreter: $ifOk:=PHP Execute("";"quit_4d_php") Error management: // Installation of the error-management method The PHP_errHandler method is as follows: phpCommError:="" Dynamic creation by 4D of a script before its execution: DOCUMENT TO BLOB("C:\\Scripts\\MyScript.php";$blobDoc) The script is then executed: $err:=PHP Execute("C:\\Scripts\\MyScript.php";"function2Rename_v2";*) Direct retrieval of a Date and Time type value. Here are the contents of the script: <?php Receiving the date on the 4D side: C_DATE($phpResult_date) Distribution of data in arrays: ARRAY TEXT($arText ;0) Initialization of an array: ARRAY TEXT($arText ;0) Passing of parameters via an array: ARRAY INTEGER($arInt;0) Here is an example of the basic use of the trim function, to remove extra spaces and/or invisible characters from the beginning and end of a string: C_TEXT($T_String) For more information concerning the trim function, please refer to the PHP documentation.
See also
Executing PHP scripts in 4D
|
PROPERTIES
Product: 4D
HISTORY
Created: 4D v12 ARTICLE USAGE
4D Language Reference ( 4D v16) |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||