4D v14.3

PHP modules support

Home

 
4D v14.3
PHP
PHP modules support

PHP modules support  


 

 

This appendix details the implementation of PHP modules in 4D. The following subjects are covered:

  • List of standard PHP modules provided by default with the PHP interpreter of 4D
  • List of standard PHP modules not retained by 4D
  • Modifications of the php.ini file.

Note: If you want to install additional modules, you must use an external FastCGI-php interpreter (see Using another PHP interpreter or another php.ini file). 

The following table details the PHP modules provided by default with 4D.

NameWeb SiteDescription
BCMathhttp://php.net/bcBinary calculator handling numbers of any size and precision represented as strings.
Example:
 C_LONGINT($value;$result)
 $value:=4
 $ok:=PHP Execute("";"bcpow";$result;$value;3)
Calendarhttp://php.net/calendarSet of functions simplifying conversion between different calendar formats. Based on Julian Day Count.
Example:
 C_LONGINT($NumberOfDays)
 $ok:=PHP Execute("";"cal_days_in_month";$NumberOfDays;1;2;2010)
Ctypehttp://php.net/ctypeFunctions that check whether a character or a string belongs to a certain character class, depending on the current local configuration
Example:
  // Check that all the characters of a string are punctuation marks
 C_TEXT($myString)
 $myString:=",.;/"
 $ok:=PHP Execute("";"ctype_punct";$isPunct;$myString)
Date and Timehttp://php.net/datetimeRecovery of the date and time from the server where the PHP script is executed
Example:
  //Calculation of time of sunrise in Lisbon, Portugal
  //Latitude: 38.4 North
  //Longitude: 9 West
  //Zenith ~= 90
  //Time-lag: +1 GMT
 C_TIME($SunriseTime)
 $ok:=PHP Execute("";"date_sunrise";$SunriseTime;0;1;38,41;-9;90;1)
DOM (Document Object Model)http://php.net/domUse of XML documents via the DOM API in PHP 5
Exifhttp://php.net/exifWork with image metadata.
Fileinfo(*)http://php.net/fileinfoDetection of type of contents and encoding of a file.
Filterhttp://php.net/filterValidate and filter data from a non-secure source, like user entries.
Example:
 C_LONGINT($filterId)
 C_TEXT($result)
 $ok:=PHP Execute("";"filter_id";$filterId;"validate_email")
 $ok:=PHP Execute("";"filter_var";$result;"hop@123.com";$filterId)
FTP (File Transfert Protocol)http://php.net/ftpDetailed access to a FTP server
Hashhttp://php.net/hashMessage Digest engine. Allows direct or incremental processing of arbitrary length messages using a variety of hashing algorithms
Example:
 C_TEXT($md5Result)
 $ok:=PHP Execute("";"md5";$md5Result;"this is my string to hash")
GD (Graphics Draw) Libraryhttp://php.net/gdWorking with images
Iconvhttp://php.net/iconvConversion of files between various character sets
JSON (JavaScript Object Notation)http://php.net/jsonImplementation of JSON data exchange format
LDAPhttp://php.net/ldapLDAP is an access protocol to "folder servers" that store information in the form of a tree diagram
LibXMLhttp://php.net/libxmlLibrary of XML functions and constants
LibXSLThttp://php.net/xslLibrary of XSL transformation functions
Multibyte Stringhttp://php.net/mbstringSet of functions for working with strings that can be used to handle multi-byte character encodings or to convert character strings.
OpenSSLhttp://php.net/opensslUse of OpenSSL functions to generate and verify signatures, to seal (encode) and open (decode) data.
PCRE (Perl Compatible Regular Expressions)http://php.net/pcreSet of functions that implement rational expressions using the same syntax and semantics Perl 5
Example:
  // This example removes unnecessary spaces from a string
 C_TEXT($myString)
 $myString:="foo       o        bar"
 PHP Execute("";"preg_replace";$myString;"/\\s\\s+/";" ";$myString)
 ALERT($myString)
  //The string is now 'foo o bar' without repeated spaces
PDO (PHP Data Objects)http://php.net/pdoInterface for accessing a database. Requires a database-specific PDO driver.
PDO_SQLITEhttp://php.net/pdo_sqliteDriver that implements the PHP Data Objects (PDO) interface to allow PHP access to SQLite 3 databases.
Reflectionhttp://php.net/reflectionComplete reflection API that lets you reverse-engineer classes, interfaces, functions and methods as well as extensions
Phar (PHP Archive)http://php.net/pharAllows a complete PHP application to be included in a unique file named "phar" (PHP Archive) to facilitate its installation and configuration
Sessionhttp://php.net/sessionSupport of PHP sessions
Example:
Sessions are used in Web applications to preserve the context between each request. When you call PHP Execute in 4D, the PHP script can start a session and store anything that is useful to be kept as context in the associated $_SESSION array. If a PHP script uses sessions, you must obtain the session ID returned by PHP using the PHP GET FULL RESPONSE command and specify it before each call to PHP Execute using the SET ENVIRONMENT VARIABLE command.
  // "PHP Execute with context" method
 If(<>PHP_Session#"")
    SET ENVIRONMENT VARIABLE("HTTP_COOKIE";<>PHP_Session)
 End if
 If(PHP Execute($1))
    PHP GET FULL RESPONSE($0;$errorInfos;$errorValues;$headerFields;$headerValues)
    $idx:=Find in array($headerFields;"Set-Cookie")
    If($idx>0)
       <>PHP_Session:=$headerValues{$idx}
    End if
 End if
SimpleXMLhttp://php.net/simpleXMLVery simple and easy-to-use tools to be used to convert XML to an object that can be processed with its properties and array iterators
Socketshttp://php.net/socketsImplementation of a low-level interface to the socket communication functions based on BSD sockets and providing the possibility to act as both a socket server as well as a client.
SPL (Standard PHP Library)http://php.net/splCollection of interfaces and classes that are meant to solve standard problems.
SQLitehttp://php.net/sqliteExtension for the SQLite database engine. This engine is embeddable.
SQLite3http://php.net/sqlite3Support for SQLite version 3 databases
Tokenizerhttp://php.net/tokenizerFunctions that let you write your own PHP analysis tools or modification tools without having to deal with the language specification at the lexical level
XML (eXtensible Markup Language)http://php.net/xmlParsing of XML documents
XMLreaderhttp://php.net/xmlreaderXML Pull parser
XMLwriterhttp://php.net/xmlwriterGeneration of XML format streams or files
Zlibhttp://php.net/zlibReading and writing of gzip (.gz) compressed files
Example:
 WEB GET HTTP HEADER($names;$values)
 $pos:=Find in array($names;"Accept-Encoding")
 If($pos>0)
    Case of
       :(Position($values{$pos};"gzip")>0)
          WEB SET HTTP HEADER("Content-Encoding: gzip")
          PHP Execute("";"gzencode";$html;$html)
       :(Position($values{$pos};"deflate")>0)
          WEB SET HTTP HEADER("Content-Encoding: deflate")
          PHP Execute("";"gzdeflate";$html;$html)
    End case
 End if
 WEB SEND TEXT($html)
Ziphttp://php.net/zipReading and writing of ZIP compressed archives and the files inside them

(*) In the current version of 4D, these modules are not available under Windows

For structural reasons, the following PHP modules are only available on the Windows platform.

NameWeb SiteDescription
COM & .NEThttp://php.net/comCOM (Component Object Model) is one of the main ways for applications and components to communicate on Windows platforms. In addition, 4D supports the instantiation and creation of .Net assemblies via the COM layer.
ODBC (Open DataBase Connectivity)http://php.net/odbcIn addition to standard ODBC support, the Unified ODBC functions in PHP gives you access to several databases that have borrowed the semantics of the ODBC API to implement their own API.
WDDX (Web Distributed Data eXchange)http://php.net/wddxFacilitates data exchanges between Web applications over the Web, regardless of the platform

The following PHP modules have not been implemented in 4D. The rightmost column gives the reason they were not implemented:

NameWeb SiteCause - Alternative solution
Mimetypehttp://php.net/mime-magicObsolete (Deprecated) - Use Fileinfo
POSIX (Portable Operating System Interface)http://php.net/posixObsolete (Deprecated)
Regular Expression (POSIX Extended)http://php.net/regexObsolete (Deprecated) - Use PCRE
Crackhttp://php.net/crackRestrictive license
ffmpeghttp://ffmpeg-php.sourceforge.net/Restrictive license - Use ffmpeg in command line with LAUNCH EXTERNAL PROCESS
Image Magickhttp://php.net/manual/book.imagick.phpRestrictive license - Use GD 2
IMAP (Internet Message Access Protocol)http://php.net/imapRestrictive license - Use the 4D Internet Commands integrated plugin
PDF (Portable Document Format)http://php.net/pdfRestrictive license - Use Haru PDF
Mysqlnd (MySQL Native Driver)http://dev.mysql.com/downloads/connector/php-mysqlnd/Not pertinent in the 4D environment

The "php.ini" file to modify (see below) can be located either in the Resources\php folder of the 4D application (default file) or in the Resources folder of the database (custom file). For more on this subject, refer to Executing PHP scripts in 4D.

Warning: Modifying the "php.ini" file must be done with caution and requires a good knowledge of PHP. For more information about the configuration of custom php.ini files, you can consult the comments found in the php.ini file provided by 4D. 

Note: If the duration of PHP processing is relatively long (beyond 30 seconds), by default a 'timeout' error will be returned in 4D and the processing will fail. In this case, you can set the default timeout in order to allocate more time to PHP execution. There are two ways to do this:

  • by setting the max_execution_time variable in the "php.ini" file (pass a value in seconds). Warning: this setting affects all the scripts.
  • by calling the set_time_limit(nbSec) command in the PHP execution script that is performing the long processing. Pass the maximum duration allocated to the execution of the PHP script in nbSec. We recommend using this setting since it only affects this script. Usually, for security reasons, it is preferable to keep a lower timeout value for PHP scripts.

 
PROPERTIES 

Product: 4D
Theme: PHP

 
ARTICLE USAGE

4D Language Reference ( 4D v14 R2)
4D Language Reference ( 4D v14 R3)
4D Language Reference ( 4D v14.3)
4D Language Reference ( 4D v14 R4)

Inherited from : PHP modules support ( 4D v12.4)
Parent of : PHP modules support ( 4D v13.5)