4D v13.4

PHP modules support

Home

 
4D v13.4
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
  • Installation instructions for additional modules.

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
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 v12. 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 interpreter leaves you the possibility of installing additional modules. This gives you access to specific functionalities that are not present by default.
You can install several types of extensions:

  • PECL (PHP Extension Community Library) extensions
  • Extensions of the PEAR (PHP Extension and Application Repository) framework
  • Extensions of the Zend framework
  • Extensions of the Symphony framework
  • Extensions of the JELIX framework
  • eZ components

Installation information for each type of extension are provided below.

Note: The characteristics of the PHP version provided with 4D v12 are as follows:

  • Version 5.3.2
  • Under Windows and Mac OS,  32-bit compilation and in "thread-safe" mode

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

Web Site: http://pecl.php.net
To add PECL extensions:

  1. Download and build the PECL extension desired.
    OR
    Take the extension already built from a PHP 5.3 VC9 Non Thread Safe Windows binary package (http://windows.php.net/download/#php-5.3-nts-VC9-x86)
  2. Add the extension into the extension folder. 
  3. Activate the extension in the "php.ini" file.

Warning: if the extensions available on the PECL Web site are under PHP license which is not restrictive, certain may require libraries which may themselves have a more restrictive license.

PHP extensions are available on other Web sites, but in this case they do not have the security guarantee provided by the validation of the PHP Group.

Web Site: http://pear.php.net
PEAR is a framework that is entirely object oriented.
To add PEAR extensions:

  1. Download (http://pear.php.net/package/PEAR/download) and uncompact the PEAR package into a folder named "pear".
  2. Add this "pear" folder in the "include_path" specified in the "php.ini" file.
  3. Download and uncompact any PEAR packages into this folder.

  1. Download (http://framework.zend.com/download/latest) and uncompact the Zend framework into a folder named "zend". 
  2. Add this "zend" folder in the "include_path" specified in the "php.ini" file. 
  3. Read the documentation for Zend framework components: http://framework.zend.com/manual/en

Web Site: http://www.symfony-project.org
The Symphony framework is structured so as to be used as a Web application accompanied by its Web controller. 

  1. Download and uncompact the source framework as well as the sandbox from the following address: http://www.symfony-project.org/installation/1_2.

  1. Download (http://jelix.org/articles/en/download/stable) and uncompact the JELIX framework.
  2. Add the resulting "jelix" folder in the "include_path" specified in the "php.ini" file.
  3. Read the documentation for JELIX framework components: http://jelix.org/articles/en/manual-1.1/components

  1. Download (http://www.ezcomponents.org/download) and uncompact the eZ components into a "ez" folder.
  2. Add the "ez" folder in the "include_path" specified in the "php.ini" file.
  3. Read the documentation for eZ components: http://www.ezcomponents.org/docs/api/latest

 
PROPERTIES 

Product: 4D
Theme: PHP