I have created a PHP extension using C++. I want to ship my extension to my clients in its binary form. That means I need to build a separate version of it for each PHP version (5.2, 5.3, 5.4, 5.5) and each processor architecture.
My questions are:
why do they keep updating the API timestamp while the API itself seemingly does not change? Wouldn't it remove a lot of headache while upgrading your system to use the next version of PHP? Just for comparison, I also have a version of my extension for MS Excel using the XLL API and that API has remained backwards compatible since 2003 which allows me to have just two binaries (32 and 64 bit) for all of my clients.
Is there any way around this problem? I.e. is there a way to build a PHP extension that can be run in multiple PHP versions?
Maybe you can try a hybrid approach. Compile your C++ library separately and then create an open source PHP extension wrapper for that. The PHP extension has nearly no logic of its own. It converts data types from PHP to C/C++ back and forth and passes the arguments to functions/methods implemented in your C++ library.
You then just maintain a binary version of your library per platform and the adoption to a particular PHP version is done by the open source PHP extension.
This of course requires that the systems of your customers do have the PHP development packages installed, as well as a compiler.
Related
I'm dealing with a legacy firebird database and can't seem to get it to work with PHP7.4.
The interbase extension isn't available anymore in PHP7.4, I can only install PDO_FIREBIRD.
There are also no releases on PECL.
https://pecl.php.net/package/interbase
Any hints how to make it work with 7.4?
Recent versions of PHP indeed no longer ship with the interbase package. Instead you can use the Firebird PHP driver, which is a fork and continued development of the interbase package.
Well, I faced some caveats while dealing with legacy Firebird data structures.
To put it simply, I had to address two broad issues:
1 - Match client libraries with dataset On-disk Structure (ODS)
Each Firebird version supports a limited range of On-Disk Structures (ODSs). The following link has a pretty nice reference on this topic:
https://ib-aid.com/en/articles/all-firebird-and-interbase-on-disk-structure-ods-versions
ADODB and PHP PDO are abstraction layers to client libraries in the host system. And PHP 7.4 supports only FB 3.0 and later clients. So, it is necessary to match the abstraction layer with the client library available.
For datasets up to FB 2.5:
disk structure should be up to ODS 11;
client version should be up to FB 2.5.9 (recommended);
PHP engine should be up to 7.3 (7.1 already has issues);
legacy functions ibase_ and fbird_ should work fine;
ADODB, PHP PDO, etc. should not work.
For datasets starting from FB 3.0:
disk structure should be ODS 12 or higher;
client version should be FB 3.0 or higher;
PHP engine should be 7.4 or higher;
legacy functions ibase_ and fbird_ should not work;
ADODB, PDO etc. should work fine.
2 - Match client and server platforms and params
For any client and server combination:
the client and the server should share the same platform, 32 or 64 bits;
the connection should use SQL dialect 1 or 3, depending on legacy dataset usage;
the character encoding should be WIN-1251 (legacy) or UTF-8 (new default).
Opinion
In my experience, it is difficult to "force" legacy FB connections into an up-to-date PHP engine. I suppose it is more challenging with Linux systems because libgcc has different entry points from versions 5 to 6 (I guess...), and musl just ain't supported.
Things are more flexible in Windows since fbclient.dll is the only client library needed for the connection, and it depends on Win32 libraries that have maintained the same entry points over the years.
I'd recommend upgrading the dataset to Firebird 4 and using updated extensions and clients. However, if this is not an option, downgrading should be streamlined from the host OS, through the PHP engine, until the FB client.
Unfortunately, I believe "this is the way."
All the best.
Recently I have problems connecting firebird with php. I went through many questions until I discovered that there has to be 3 dll's inside the apache bin folder. gds32.dll
msvcr71.dll
fbclient.dll.
Without these dll's it doesn't work, for some unknown reason the new version of xampp came missing.
I'm dealing with a legacy firebird database and can't seem to get it to work with PHP7.4.
The interbase extension isn't available anymore in PHP7.4, I can only install PDO_FIREBIRD.
There are also no releases on PECL.
https://pecl.php.net/package/interbase
Any hints how to make it work with 7.4?
Recent versions of PHP indeed no longer ship with the interbase package. Instead you can use the Firebird PHP driver, which is a fork and continued development of the interbase package.
Well, I faced some caveats while dealing with legacy Firebird data structures.
To put it simply, I had to address two broad issues:
1 - Match client libraries with dataset On-disk Structure (ODS)
Each Firebird version supports a limited range of On-Disk Structures (ODSs). The following link has a pretty nice reference on this topic:
https://ib-aid.com/en/articles/all-firebird-and-interbase-on-disk-structure-ods-versions
ADODB and PHP PDO are abstraction layers to client libraries in the host system. And PHP 7.4 supports only FB 3.0 and later clients. So, it is necessary to match the abstraction layer with the client library available.
For datasets up to FB 2.5:
disk structure should be up to ODS 11;
client version should be up to FB 2.5.9 (recommended);
PHP engine should be up to 7.3 (7.1 already has issues);
legacy functions ibase_ and fbird_ should work fine;
ADODB, PHP PDO, etc. should not work.
For datasets starting from FB 3.0:
disk structure should be ODS 12 or higher;
client version should be FB 3.0 or higher;
PHP engine should be 7.4 or higher;
legacy functions ibase_ and fbird_ should not work;
ADODB, PDO etc. should work fine.
2 - Match client and server platforms and params
For any client and server combination:
the client and the server should share the same platform, 32 or 64 bits;
the connection should use SQL dialect 1 or 3, depending on legacy dataset usage;
the character encoding should be WIN-1251 (legacy) or UTF-8 (new default).
Opinion
In my experience, it is difficult to "force" legacy FB connections into an up-to-date PHP engine. I suppose it is more challenging with Linux systems because libgcc has different entry points from versions 5 to 6 (I guess...), and musl just ain't supported.
Things are more flexible in Windows since fbclient.dll is the only client library needed for the connection, and it depends on Win32 libraries that have maintained the same entry points over the years.
I'd recommend upgrading the dataset to Firebird 4 and using updated extensions and clients. However, if this is not an option, downgrading should be streamlined from the host OS, through the PHP engine, until the FB client.
Unfortunately, I believe "this is the way."
All the best.
Recently I have problems connecting firebird with php. I went through many questions until I discovered that there has to be 3 dll's inside the apache bin folder. gds32.dll
msvcr71.dll
fbclient.dll.
Without these dll's it doesn't work, for some unknown reason the new version of xampp came missing.
This isn't particularly a coding question.
I have a script running locally (PHP V5.6) and it's absolutely perfect.
However, I FTPd it to our dev server to run as a cron and it failed. Our server has php v5.5 running for dependancy issues. Is there any way I can user composer require to install phpspreadsheet on a machine running PHP 5.5?
PHPSpreadsheet was deliberately written for PHP >=5.6.0 because I was fed up with the way people had made death threats to me for even suggesting that the minimum version of PHP required to run its predecessor (PHPExcel) should be increased from PHP 5.2 to take advantage of newer features of the language to reduce the codebase and memory footprint, and make it more performant
PHPSpreadsheet uses features of PHP that are only available in PHP 5.6 or above, and will soon drop support for even that version when Security support ends for that version of PHP on 31 Dec 2018, and require a minimum of PHP 7.1.0
If you need to create spreadsheets using older unsupported versions of PHP, then you can't use PHPSpreadsheet, and can only use its predecessor PHPExcel
No, PhpSperadsheet requires v5.6 or above.
In the docs # https://phpspreadsheet.readthedocs.io/en/develop/
Software requirements
The following software is required to develop using PhpSpreadsheet:
**PHP version 5.6 or newer**
PHP extension php_zip enabled
PHP extension php_xml enabled
PHP extension php_gd2 enabled (if not compiled in)
Try upgrading PHP.
I have the source for a PHP extension, and the compiled version for PHP 5.3. But I have PHP 5.4, and the project appears to have been abandoned.
So given the source code, what is the minimum I have to do to compile it for PHP 5.4?
EDIT Note: I'm on Windows.
It depends on the extension itself. If the extension requires some other libraries, like, say the mysql extension, then you also need the mysql client library - the C API. Why? Because you explicitly stated that you want minimal dependency requirements. If the extension does not require any other libraries, you can nicely open those C files that you already have, and compile it using any available C compiler. Naturally, you will need PHP development kit as well. :)
I have my application written on PHP/MYSQL. We are looking at option for deployment at client site machine. What is the option and how to do it? Apart from that we are more concern about protecting our code. Hence, we're looking at the option that can make a binary application for our web application developed on php/mysql.
Apart from that is there any installer available that can extract and install php/apache/mysql stack ?
See this previous response to a similar question for a comprehensive list of the options available for compiling/wrapping PHP code as an executable for Windows
Other options available for non-Windows:
HPHP (Facebook's HipHop)
https://github.com/facebook/hiphop-php/wiki/
https://github.com/facebook/hiphop-php
HipHop for PHP is a source code transformer for PHP script code. HipHop programmatically transforms PHP source code into highly optimized C++ and then uses g++ to compile it to machine code. HipHop includes a code transformer, a reimplementation of PHP's runtime system, and a rewrite of many common PHP Extensions to take advantage of these performance optimizations.
HipHop was created by Facebook to save resources on its servers. It is being distributed with its over 300,000 lines of source code written in C++ and C as free software under the terms of version 3.01 of the PHP License.
Facebook has also developed HPHPi, which is an experimental interpreter designed for development with no need to compile the PHP source code before running it.
Roadsend and Roadsend Raven
http://www.roadsend.com/home/index.php
https://github.com/weyrick/roadsend-php/wiki
https://github.com/weyrick/roadsend-php
Roadsend PHP is an open source implementation of the PHP language. It compiles PHP source code to stand alone, native binaries which do not require an interpreter. Roadsend Compiler can build online web applications with Fast/CGI, offline web applications with an embedded web server (!MicroServer), desktop GUI applications with PHP-GTK, and console applications. It is known to build on Linux, Windows (using mingw), Mac OSX, and FreeBSD.
Roadsend Compiler also contains facilities for interpreting, profiling and step debugging PHP code.
Roadsend PHP is a completely independent implementation of the PHP language and runtime environment, and is not based on the original implementation (using the Zend engine) which is separately and freely available at http://www.php.net. Zend PHP is not required, and is not used in any way, by Roadsend PHP.
Last change to the roadsend code was 17 months ago (a patch for Ubuntu 10.04 llvm package), prior to that was 21 months ago. Readme's have been updated in the last two weeks (at time of writing this) so perhaps it's about to be resurrected again.
Can build Linux executables
Phalanger
http://www.php-compiler.net/
http://wiki.php-compiler.net/Phalanger_Wiki
http://phalanger.codeplex.com/
Phalanger is a project which was started at Charles University in Prague and was supported by Microsoft. It compiles source code written in the PHP scripting language into CIL (Common Intermediate Language) byte-code. It handles the beginning of a compiling process which is completed by the JIT compiler component of the .NET Framework. It does not address native code generation nor optimization. Its purpose is to compile PHP scripts into .NET assemblies, logical units containing CIL code and meta-data.
phc
http://www.phpcompiler.org/
phc is an open source compiler for PHP with support for plugins. In addition, it can be used to pretty-print or obfuscate PHP code, as a framework for developing applications that process PHP scripts, or to convert PHP into XML and back, enabling processing of PHP scripts using XML tools.
phc for PHP programmers (See Manual):
Compile PHP source into an (optimized) executable (supports entire
PHP standard library).
Compile a web application into an (optimized)
extension (supports entire PHP standard library).
Obfuscate PHP code (--obfuscate flag - experimental). Combine
many php scripts into a single file (--include flag - experimental).
Last change to the phc code was on 18th December, so sill actively ongoing development.
Can build Linux executables
Can be used to build C code, with appropriate PHP "macros" for extensions
ROSE Compiler
http://rosecompiler.org/
Dependent on phc compiler for working with PHP
Look at PHP obfuscators, examples:
http://www.seocompany.ca/software/free-encryption-software.html
https://stackoverflow.com/questions/908678/is-there-any-good-php-obfuscator
Obfuscators aren't 100% but they are easy to implement and the output is pretty gnarly.
I am not sure about windows but on Linux you can try using Facebook's HipHop project, Of cource if you are not using eval() and other functions. Get more info and how to on Facebook Hiphop PHP - git
Any installer for "php/apache/mysql" stack? yes there is one EasyPHP, you can get the portable(extract and run) version too.
If you can do some R&D try using vmware ThinApp for windows platform. With VMware ThinApp, applications are packaged into single executables that run completely isolated from each other and the operating system