Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/miyako/4d-topic-php
Setup PHP for 4D
https://github.com/miyako/4d-topic-php
4d php
Last synced: about 1 month ago
JSON representation
Setup PHP for 4D
- Host: GitHub
- URL: https://github.com/miyako/4d-topic-php
- Owner: miyako
- License: mit
- Created: 2023-08-28T21:45:16.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-02-09T03:54:11.000Z (11 months ago)
- Last Synced: 2024-02-09T04:36:44.666Z (11 months ago)
- Topics: 4d, php
- Language: C
- Homepage:
- Size: 28.2 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![version](https://img.shields.io/badge/version-20%2B-E23089)
# 4d-topic-php
Setup PHP for 4D## Build static PHP with minimal dependencies
Clone or download [php-src](https://github.com/php/php-src).
By default, `re2c` is missing and `bison` is too old.
```
brew install re2c
brew install bison
echo 'export PATH="/opt/homebrew/opt/bison/bin:$PATH"' >> ~/.zshrc
```Restart Terminal.
```
cd {php-src-master}
autoreconf
export LIBS="-lz"
/configure --enable-static --without-iconv --prefix={path-to-install-dir}
make
make install
```This will install static `php-cgi` with only the following system dependencies:
```
/usr/lib/libresolv.9.dylib
/usr/lib/libnetwork.dylib
/usr/lib/libSystem.B.dylib
/usr/lib/libz.1.dylib
/usr/lib/libsqlite3.dylib
```For comparision, the v20 `php-fcgi-4d` file looks like this:
```
/usr/lib/libresolv.9.dylib
/usr/lib/libnetwork.dylib
/usr/lib/libSystem.B.dylib
```According to the [PHP modules support](https://doc.4d.com/4Dv20/4D/20/PHP-modules-support.300-6238471.en.html) documentation, `SQLite3` is enabled so the library must be statically linked. `Zip`, `Zlib`, `Iconv`, as well as XML-releated featured that depend on `Zlib` are all disabled.
To create universal binary, restart Terminal using Rosetta, `make distclean`, repeat, then `lipo -create`.
## Build static PHP with embedded `libz` and `libsqlite3`
Download libraries, then `lipo -create`:
```
brew fetch --bottle-tag=arm64_big_sur sqlite
brew fetch --bottle-tag=x86_64_big_sur sqlite
brew fetch --bottle-tag=arm64_big_sur zlib
brew fetch --bottle-tag=x86_64_big_sur zlib
```Indicate static library location:
```
export LDFLAGS="-L{path-to-static-library-dir}"
export LIBS="-lz -lsqlite3"
```**Error**: `sqlite3.c:446:6: error: call to undeclared function 'sqlite3_load_extension'`
c.f. https://bugs.python.org/issue44997
We could edit */ext/sqlite3/sqlite3.stub.php* like so:
```c
#ifndef SQLITE_OMIT_LOAD_EXTENSION
/** @tentative-return-type */
# public function loadExtension(string $name): bool {}
#define SQLITE_OMIT_LOAD_EXTENSION 1
#endif
```
…but this won't update the source files.**Solution**: Remove from *ext/sqlite3/sqlite3_arginfo.h*
```c
#if !defined(SQLITE_OMIT_LOAD_EXTENSION)
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SQLite3_loadExtension, 0, 1, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
ZEND_END_ARG_INFO()
#endif
```…and add to *ext/sqlite3/sqlite3.c*
```c
#define SQLITE_OMIT_LOAD_EXTENSION 1
```This will install static `php-cgi` with the same 3 dependencies as `php-fcgi-4d`.
## Build static PHP with embedded `libiconv`
Download libraries, then `lipo -create`:
```
brew fetch --bottle-tag=arm64_big_sur libiconv
brew fetch --bottle-tag=x86_64_big_sur libiconv
```**Error**: `configure: error: Please reinstall the iconv library.`
Indicate static library location:
We could indicate static library location. Also add `-liconv` to `LDFLAGS`:
```
export CFLAGS="-I{path-to-user-header-dir}"
export LDFLAGS="-L{path-to-static-library-dir} -liconv"
export LIBS="-lz -lsqlite3 -liconv"
```…but this won't eliminate compiler errors.
**Solution**: Remove `#undef` *ext/iconv/iconv.c*
```c
#ifdef HAVE_LIBICONV
//#undef iconv
#endif
```## Does it actually work?
Rename the program as `php-fcgi-4d` and replace the one inside 4D.app.
Test call:
```4d
var $returnValue : Text$success:=PHP Execute(""; "phpversion"; $returnValue)
var $response : Text
ARRAY TEXT($labels; 0)
ARRAY TEXT($values; 0)PHP GET FULL RESPONSE($response; $labels; $values)
```**Result**: `$success` is `False`. Activity Monitor shows multiple instances of `php-fcgi-4d`. `X-4DPHP-Error-php-interpreter` contains the message:
```
PHP Fatal error: Uncaught Error: Call to undefined function mb_convert_encoding() in _4D_Execute_PHP.php:131
```**Solution**: Add `--enable-mbstring` to `configure`.
## Build static PHP with embedded `libzip`
The homebrew distribution of [libzip](https://formulae.brew.sh/formula/libzip) is dynamic-only.
**Solution**: Build from [source](https://github.com/nih-at/libzip). Uncheck `BUILD_SHARED_LIBS` in CMake.
## Build static PHP with modules and extensions
|Modules or Extension|Configure Option|4D v20|This Repository|
|-|-|:-:|:-:|
|[BCMath](https://www.php.net/manual/en/book.bc.php)|`--enable-bcmath`|
- - [x]
- - [x]
|[Calendar](https://www.php.net/manual/en/book.calendar.php)|`--enable-calendar`|
- - [x]
- - [x]
|[Character type checking](https://www.php.net/manual/en/book.ctype.php)|(default)|
- - [x]
- - [x]
|[Client URL Library](https://www.php.net/manual/en/book.curl.php)|`--with-curl=DIR`|*disabled*|
- - [x]
|[Date and Time](https://www.php.net/manual/en/book.datetime.php)|(default)|
- - [x]
- - [x]
|[Document Object Model](https://www.php.net/manual/en/book.dom.php)|(default)|*disabled*|
- - [x]
|[Exchangeable image information](https://www.php.net/manual/en/book.exif.php)|`--enable-exif`|
- - [x]
- - [x]
|[File Information](https://www.php.net/manual/en/book.fileinfo.php)|(default)|
- - [x]
- - [x]
|[Data Filtering](https://www.php.net/manual/en/book.filter.php)|(default)|
- - [x]
- - [x]
|[FTP](https://www.php.net/manual/en/book.ftp.php)|`--enable-ftp`|
- - [x]
- - [x]
|[GNU Multiple Precision](https://www.php.net/manual/en/book.gmp.php)|`--with-gmp`|*disabled*|
- - [x]
|[HASH Message Digest Framework](https://www.php.net/manual/en/book.hash.php)|(default)|
- - [x]
- - [x]
|[iconv](https://www.php.net/manual/en/book.iconv.php)|(default)|*disabled*|
- - [x]
|[Image Processing and GD](https://www.php.net/manual/en/book.image.php)|`--enable-gd --with-avif --with-webp --with-jpeg --enable-gd-jis-conv`|*disabled*|
- - [x]
|[JavaScript Object Notation](https://www.php.net/manual/en/book.json.php)|(default)|
- - [x]
- - [x]
|[libxml](https://www.php.net/manual/en/book.libxml.php)|(default)|*disabled*|
- - [x]
|[Lightweight Directory Access Protocol](https://www.php.net/manual/en/book.ldap.php)|`--with-ldap`|
- - [x]
- - [x]
|[Multibyte String](https://www.php.net/manual/en/book.mbstring.php)|`--enable-mbstring`|
- - [x]
- - [x]
|[OpenSSL](https://www.php.net/manual/en/book.openssl.php)|`--with-openssl`|
- - [x]
- - [x]
|[Regular Expressions (Perl-Compatible)](https://www.php.net/manual/en/book.pcre.php)|(default)|
- - [x]
- - [x]
|[PHP Data Objects](https://www.php.net/manual/en/book.pdo.php)|(default)|
- - [x]
- - [x]
|[SQLite Functions (PDO_SQLITE)](https://www.php.net/manual/en/ref.pdo-sqlite.php)|(default)|
- - [x]
- - [x]
|[Phar](https://www.php.net/manual/en/book.phar.php)|(default)|
- - [x]
- - [x]
|[POSIX](https://www.php.net/manual/en/book.posix.php)|(default)|
- - [x]
- - [x]
|[Random Number Generators and Functions Related to Randomness](https://www.php.net/manual/en/book.random.php)|(default)|
- - [x]
- - [x]
|[Reflection](https://www.php.net/manual/en/book.reflection.php)|(default)|
- - [x]
- - [x]
|[Sessions](https://www.php.net/manual/en/features.sessions.php)|(default)|
- - [x]
- - [x]
|[SimpleXML](https://www.php.net/manual/en/book.simplexml.php)|(default)|*disabled*|
- - [x]
|[Sockets](https://www.php.net/manual/en/book.sockets.php)|`--enable-sockets`|
- - [x]
- - [x]
|[SQLite3](https://www.php.net/manual/en/book.sqlite3.php)|(default)|
- - [x]
- - [x]
|[Standard PHP Library (SPL)](https://www.php.net/manual/en/book.spl.php)|(default)|
- - [x]
- - [x]
|[Tidy](https://www.php.net/manual/en/book.tidy.php)|`--with-tidy=DIR`|*disabled*|
- - [x]
|[Tokenizer](https://www.php.net/manual/en/book.tokenizer.php)|(default)|
- - [x]
- - [x]
|[XML Parser](https://www.php.net/manual/en/book.xml.php)|(default)|*disabled*|
- - [x]
|[XMLReader](https://www.php.net/manual/en/book.xmlreader.php)|(default)|*disabled*|
- - [x]
|[XMLWriter](https://www.php.net/manual/en/book.xmlwriter.php)|(default)|*disabled*|
- - [x]
|[Zip](https://www.php.net/manual/en/book.zip.php)|`--with-zip`|*disabled*|
- - [x]
|[Zlib Compression](https://www.php.net/manual/en/book.zlib.php)|`--with-zlib`|*disabled*|
- - [x]
### Configure Options
```
./configure
--with-tidy=DIR
--with-ldap=DIR
--with-curl=DIR
--with-openssl=DIR
--with-zlib
--with-gmp
--with-zip
--enable-static
--enable-bcmath
--enable-calendar
--enable-exif
--enable-ftp
--enable-gd --with-avif --with-webp --with-jpeg --enable-gd-jis-conv
--enable-sockets
--enable-mbstring
```
### Static Libraries and Frameworks
```
export LIBS="
-lz
-lsqlite3
-liconv
-lbz2
-lzip
-lzstd
-lonig
-llzma
-lgd
-lwebp -lavif -ltiff -lpng16 -lsharpyuv
-ltidy
-lgmp
-lcrypto -lssl
-lcurl -lnghttp2 -lidn2 -lssh2 -lldap -llber
-lbrotlidec -lbrotlienc -lbrotlicommon
-lsasl2
-lunistring
-lrtmp
-framework GSS
-framework SystemConfiguration
-framework Cocoa
-framework Security
-framework LDAP
-framework Kerberos"
```
## Build static PHP with embedded `libcurl`
**Error**: `configure: error: There is something wrong. Please check config.log for more information.`
**Solution**: Add path to custom installations:
```
./configure
--with-curl=DIR
--with-openssl=DIR
```
**Error**: Undefined symbols: `libunistring` expects a non-plug version of `libiconv`.
**Solution**: Compile and use a hybrid version that contains both names (`_iconv` and `_libiconv`).
**Error**: Undefined symbols: `libbrotli` constants.
**Solution**: Specify subdirectory paths to header files:
```
export CFLAGS="
-I{path-to-user-header-dir}
-I{path-to-user-header-dir}/brotli
-I{path-to-user-header-dir}/curl"
```
## Build static PHP with embedded `libldap`
**Error**: `configure: error: Cannot find ldap.h`
**Solution**: Add path to custom installations:
```
./configure
--with-ldap=DIR
```
## Build static PHP with [interactive shell](https://www.php.net/manual/en/features.commandline.interactive.php) support
**Error**: `configure: error: Please reinstall readline - I cannot find readline.h`
**Solution**: Add path to custom installations:
```
--with-readline=DIR
```