How do I compile on linux to share with all distributions? - php

I compiled a PHP extension on Fedora Core 12, but when I send it to someone using CentOS they get the error: "ELF file OS ABI invalid"
I'm not sure what causes this running file provides the following info:
ELF 64-bit LSB shared object, AMD x86-64, version 1 (GNU/Linux), not stripped
An extension that loads fine provides the following from file:
ELF 64-bit LSB shared object, AMD x86-64, version 1 (SYSV), not stripped
So it seems I need to generate a SYSV type file for some distributions, instead of a GNU/LINUX file, no idea how though. Any pointers?
Also should I be statically linking?

The statement: "ELF file OS ABI invalid", means that the Application Binary Interface is non compatible between binaries used (i.e. one is trying to mix host and target binaries, which may not work as expected). The e_ident[EI_OSABI] byte of the ELF header contains the operating system/ABI identification. Your Fedora system is setting this to ELFOSABI_LINUX (3) while your friend's CentOS system is setting it to ELFOSABI_SYSV (ELFOSABI_NONE or 0).
You may be able to compile the FreeBSD brandelf utility (brandelf.c) and use it to set the OSABI to ELFOSABI_SYSV (brandelf -f 0 <file> or brandelf -t SVR4 <file>.
I am not aware of any gcc flags for specifying this value at compile/link time. I believe that the version of binutils used by gcc on your Fedora system is responsible for setting the OSABI to Linux. It is my understanding that the linker only specifies the ABI if a STT_GNU_IFUNC symbol ends up in the output file (see ifunc.txt at http://groups.google.com/group/generic-abi for details on STT_GNU_IFUNC).
The readelf(1) command can be used to retrieve and display the ABI information stored in the ELF header (readelf -h <file>).
This similar question may also be of interest.

Compiled object files don't usually transfer well between different linux distributions. Different Distributions often have different policies regarding libraries, where they're stored, how they're loaded.
There's so many differences between them (yes, even in Fedora & RedHat/CentOS). They're likely to supply their own patches to componenets at every level (kernel, PHP, library location). If they're using the distribution PHP package, the distribution might have patched it better intergrate into their system.
The major issue you'll likely run into is that the distribution have used a different libraries/compiler settings. Check to see what verision gcc is on his computer and compare it to what's on yours. (Fedora 12 has quite a few newer libraries than CentOS). That's where your issue might be.
Another possible issue is that your binary is fine, but its incompatible with all the libraries it uses. I'm not sure if there's a good way to get around this one without compiling on the target-distribution (or a varient). You can see what libraries each shared object/executable uses by using the lld <file> command.
Also, was there any output before the error ELF file OS ABI invalid? Most places I see it being referenced there's more information than that.

It's most likely that your friend is not running a 64-bit system. ELF is the standard format for Linux executables, but 32-bit systems can't run 64-bit executables.
Get the output for uname -a from your friend. If the output doesn't contain "x86_64", then he's on a 32-bit version of CentOS.
If so, you either need to set up a cross-compiling environment, or a virtual machine for compiling 32-bit binaries on, or just provide your friend with the sources so that he can compile it himself.

Related

What does actually mean by the frequently used term "PHP binary"?

I'm using Windows 10 Home Single Language 64-bit Operating System on my laptop.
I've installed the latest version of XAMPP on my laptop.
This has installed PHP 7.2.8 and Apache/2.4.34 (Win32) OpenSSL/1.1.0h PHP/7.2.8 on my laptop.
I come across following sentence from PHP Manual Page :
PHP can be used on all major operating systems, including Linux, many
Unix variants (including HP-UX, Solaris and OpenBSD), Microsoft
Windows, macOS, RISC OS, and probably others. PHP also has support for
most of the web servers today. This includes Apache, IIS, and many
others. And this includes any web server that can utilize the FastCGI
PHP binary, like lighttpd and nginx.
From the above text I didn't get the exact meaning of the term "PHP binary". This peculiar term is used very frequently at many places in the PHP Manual but nowhere the actual meaning of "PHP binary" has been given.
I googled it for the meaning and I come to know about the 'predefined constant' PHP_BINARY.
So, I tried to execute the below code in hope to clear my doubt over the actual meaning of the frequently used term "PHP binary" and checked the output in my web browser:
<?php
echo PHP_BINARY;
?>
Surprisingly, I got the below output :
C:\xampp\apache\bin\httpd.exe
I got surprised to see this output because in output I got complete address of the Apache file httpd.exe. I was expecting to get something about PHP but I got Apache file's address. Why so?
So, what does ultimately mean is I still don't understand what does actually mean by the frequently used term "PHP binary"?
I still don't have any idea about what does actually mean by the very frequently used term "PHP binary"?
Someone, please clear my doubt about the frequently used term "PHP binary" in an easy to understand, simple and lucid language.
I'm waiting for your help.
The compiled version of any program is commonly referred to as it's "binary".
PHP has multiple binaries for multiple purposes.
php.exe is used to run scripts locally in your Command Prompt;
php-cgi.exe is compliant with FastCGI protocol;
php7apache2_4.dll is PHP wrapped as an Apache 2.4 module;
And a few others too.
In this case the docs are referring to php-cgi.exe
The constant PHP_BINARY contains the path of the binary where PHP is currently executing from. Since XAMPP uses Apache, and Apache is most likely using PHP in it's Apache module form, it makes sense that httpd.exe is recognized as the binary, since it is loading php7apache2_4.dll.
PHP itself is running as a program on your computer (often referred to a binary).
Supposed we were on Windows, the PHP binary would probably be php.exe. Essentially, PHP itself.
Note that the PHP binary could be a server module... a DLL or similar.

Memcache PHP extension on windows 10 works intermittently

I have memcache extensions on apache/php windows 10 (details at the end)
Created a simple test:
$memcache = new Memcache;
$memcache->addServer("ext-memcached.e-memcached.xxx.net",11211);
$memcache->addServer("ext-memcached.e-memcached2.xxx.net",11211);
$memcache->addServer("ext-memcached.e-memcached3.xxx.net",11211);
$key='xxx_54921';
$settings = $memcache->get($key);
print_r ($settings);
the memcache servers are on AWS and they work well (production servers).
This test code works - it retreives the value from the memcache servers.
However if I wait a couple minutes and refresh it will not return value.
Then if I refresh again it will return the value.
The same code/config works from another dev computer.
What can cause this?
Config:
PHP Version 5.6.34
Windows NT SPECTRE 6.2 build 9200 (Windows 8 Home Premium Edition) i586
Build Date Feb 28 2018 17:45:55
Compiler MSVC11 (Visual C++ 2012)
Architecture x86
Memcache extension:
ts x86 version from here:
https://windows.php.net/downloads/pecl/releases/memcache/3.0.8/
memcache info:
memcache support enabled
Version 3.0.8
Revision $Revision: 329835 $
Directive Local Value Master Value
memcache.allow_failover 1 1
memcache.chunk_size 32768 32768
memcache.compress_threshold 20000 20000
memcache.default_port 11211 11211
memcache.hash_function crc32 crc32
memcache.hash_strategy standard standard
memcache.lock_timeout 600 600
memcache.max_failover_attempts 20 20
memcache.protocol ascii ascii
memcache.redundancy 1 1
memcache.session_redundancy 2 2
The memcached service doesn't actually install the PHP memcached extension for you. It only installs the memcached server used to store your cache.
You'll need to download the Windows DLL from the PECL repository first (click on the blue Windows DLL link). Then you must add the extension=php_memcache.dll line to the correct php.ini file for your SAPI. Also, note the extension DLL file needs to be placed in the correct path for your XAMPP installation.
For Apache, simply create a script in your document root with the line
For the CLI SAPI, you can use php.exe --ini to do the same. Again, you may need to rely on the XAMPP package if it has modified your configuration path (since this is a compile time directive).
After making your changes to php.ini you will need to restart PHP for the changes to take effect.
You can refer: https://pureform.wordpress.com/2008/01/10/installing-memcache-on-windows-for-php/
Since you're using PHP 7 on Windows it's probably also important to note that the compiled DLL from PECL may not actually work under apache for Windows, because you're more than likely using a theaded SAPI. So make sure you are downloading the correct version. As far as I can tell that version is only compiled to work with up to PHP 5.6. The github alternative, for PHP 7, available at https://github.com/nono303/PHP7-memcahe-dll as mentioned in the comments is tested under non-thread safe. So you may only be able to get this working for your CLI scripts on Windows.
The problem seems to be more in the way you are writing (set) and getting (get) the data having multiple nodes. - Memcache does not support replication.
Try a single node, in that case, you should be available to get the data just after being set.
When having multiple nodes "sharding" is a common approach to store the data, this means that a logic is implemented in place to determine what server to use for either writing or getting the data:
From https://en.wikipedia.org/wiki/Memcached:
Clients use client-side libraries to contact the servers which, by default, expose their service at port 11211. Both TCP and UDP are supported. Each client knows all servers; the servers do not communicate with each other. If a client wishes to set or read the value corresponding to a certain key, the client's library first computes a hash of the key to determine which server to use. This gives a simple form of sharding and scalable shared-nothing architecture across the servers.
Therefore in PHP client you could try a consistent hashing:
$memcache = new Memcache;
$memcache->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE, true);
From: http://www.php.net/manual/en/memcached.constants.php
Memcached::OPT_LIBKETAMA_COMPATIBLE
Enables or disables compatibility with libketama-like behavior. When enabled,
the item key hashing algorithm is set to MD5 and distribution is set
to be weighted consistent hashing distribution. This is useful because
other libketama-based clients (Python, Ruby, etc.) with the same server
configuration will be able to access the keys transparently.
Note:
It is highly recommended to enable this option if you want to use
consistent hashing, and it may be enabled by default in future releases.
Also, try:
memcache.hash_strategy = consistent;
Check this post for more details: https://blog.fedecarg.com/2008/12/24/memcached-consistent-hashing-mechanism/
and this answer: https://stackoverflow.com/a/48006009/1135424
Check your
memcache.redundancy memcache.redundancy
setting, your data is not be available on every memcached node. Setting it to 3 should be sufficient in your example case.

What does actually mean by 'PHP binary distributions for Windows'? How it is different from PHP source code?

I come across following statement from PHP Manual
PHP source code and binary distributions for Windows can be found at »
http://www.php.net/downloads.php. We recommend you to choose a »
mirror nearest to you for downloading the distributions.
This statement has created following doubts in my mind :
What does actually mean by 'PHP binary distributions for Windows'?
Why there are no such 'PHP binary distributions' for other operating systems like Linux, Mac OS X, RISC OS, and others?
I've installed PHP 7.2.3 on my machine running on Windows 10 operating system with the latest copy of XAMPP package then have I installed the 'PHP binary distributions for Windows'?
What's the use/need/necessity/benefit/advantage of the 'PHP binary distributions for Windows'?
Are the 'PHP binary distributions for Windows' available for download only on official PHP website?
How the 'PHP binary distributions for Windows' is different from PHP source code with reference to the above statement from PHP Manual?
Someone please clear all of my above doubts in an easy to understand language.
A binary distribution is an executable program for an operating system like Windows. Different operating systems and different prozessors need different approaches to run programs. Thus there are different distributions, that are generated differently.
see 1.
It depends on the xampp version, but yes the latest xampp does have version 7.2.3 of php (you don't need to install it again if as long as you are working in the xampp environment)
You need it to develop php code on you local machine. There are other ways, which might be a bit more complex for your level of knowledge. The binaries work mostly out of the box, more or less.
There are others, like in the xampp package, but the php website is generally the best source for it.
Source code is the program code from which the binaries are build. You can not use it as is.

php pdo_informix on windows 7 64 bit and wamp 64 bit

I try to install pdo_informix in WAMP 64 bit on windows 7 64 bit, but I found problem because pdo_informix.dll is version 32 bit. I try to search for pdo_informix.dll, but I can't found it. How to solve this problem?
Thank you for help.
It looks as though you may have to download the source for PDO Informix and compile it; that is always an available option for open source (get the code and compile it) but it presumes you have the facilities needed to compile code.
A Google search with the terms 'pdo informix 64-bit windows' picks up this question, amongst others, and also points to the PDO Informix manual which includes links to 'how to compile PDO extensions' etc.
Google also lists a IIS forum posting on the subject which says (lightly edited):
As an alternative, there is a simpler option; however, it may not be ideal depending on your requirements. There is a tool called OpenAdmin Tool for Informix. This is a PHP-based tool for administrative tasks on an Informix database. The tool is a ready-built Apache webserver with PHP set up which uses the Informix pdo driver (it is actually embedded), however, the rest of it is the same, you could copy any extra extensions/modules from your existing setup over to the OpenAdmin PHP directory and enable them in the OpenAdmin php.ini file.Then put whatever ever resides in your existing htdocs folder into the OpenAdmin htdocs folder.
It lists links to the IBM site for OAT (OpenAdmin Tool), but the links embed the date 2006-01-26, so they're probably not current and likely not directly available. The latest information is available from the OpenAdmin Tool website.
OAT does not seem to be distributed for 64-bit Windows specifically.
I also have the same problem right now.
The OpenAdmin Tool website says that the Informix Client SDK which is available on the IBM website includes a ready-to-use OpenAdmin Tool including Apache Webserver, PHP and the pdo_informix extension.
However, the current SDK 4.10 is NOT shipped with the OpenAdmin Tool.
So you have to set up your own environment with Apache and PHP and the community edition of OpenAdmin Tool. I tried Apache 2.4 for x_86 and x_64 Systems (Windows) and all available Versions of PHP (5.4, 5.5, 5.6).
You can download the pdo_informix extension for PHP 5.4 here:
https://pecl.php.net/package/PDO_INFORMIX/1.3.1/windows
And there was a guy who compiled it for PHP 5.5:
https://github.com/maryo/php-5.5-windows-extensions/tree/master/php_pdo_informix-1.3.1-5.5-vc11-x86
There is also a hint that it is very important to set the INFORMIXDIR environment variable correctly. I tried several possibilities such as C:\Program Files\IBM Informix Software Bundle\ or with a trailing \bin but it did not help.
Unfortunately, nothing worked for me. The pdo_informix extension did not load. Hopefully I can help someone with my explanations to get the OAT up and running.

Generate custom Windows-based EXE installer from *nix webserver on the fly (OpenVPN client custom installer)

This is related to this other question. I need to dynamically generate a custom Windows EXE installer from a *nix machine (running PHP, or whatever) that contains custom files to be installed on the client's machine.
This will be used to generate client-specific OpenVPN installers based on their preferences and authentication information. Runtime is not important, as it can be done async.
Some ideas, already tried and not working:
Use a scheme similar to ninite.com, where the downloaded executable is always the same, but the filename is different, so the installer uses the information in the filename to make decisions.
Using a resource editor to edit a prebuilt installer's resources. Not only are unix resource editors for windows executable rare, it also creates new problems, and don't solve the problem of different files being installed.
What would work best is a NSIS/InnoSetup compiler (targeting Windows) running on UNIX, but other inventive solutions are okay.
Answering my own question, it seems that both NSIS (used by default on OpenVPN source code) and Inno Setup can run on Linux.
Inno Setup can be used under Wine, it's a command line utility so it's really simple and works. See http://katastrophos.net/andre/blog/2009/03/16/setting-up-the-inno-setup-compiler-on-debian/
NSIS actually has a native Unix port, it's available as "nsis" package on Ubuntu/Debian. It has the "makensis" available, which can compile (on Unix) the windows executable from a .nsi file.
Just for info, I can compile a complete .exe installer in under 5 seconds, including all the dynamic stuff. PHP is used to exec() the build after preparing it, and sends the exe as a download to the client.
I suppose this (or something very similar) is how it works in the commercial OpenVPN server offering.

Categories