termux / termux-packages

A package build system for Termux.
https://termux.dev
Other
13.09k stars 3k forks source link

Compile PHP with pthreads #892

Open TheDiamondYT1 opened 7 years ago

TheDiamondYT1 commented 7 years ago

Please can this be done, or at least tell me how to do it on termux.

vaites commented 7 years ago

pcntl is not enough? Is enabled in current build...

TheDiamondYT1 commented 7 years ago

The software I'm trying to run requires pthreads

robertvalik commented 7 years ago

I believe the MariaDB package is working - #216 . It would be great to have pdo_mysql!

robertvalik commented 7 years ago

I see, I believe that I have been writing it in the pdo_mysql thread - must have messed it up somehow... Sorry.

PokeyvalGamer commented 7 years ago

How to install pthreads ?

vaites commented 7 years ago

The extension probably must be patched because of the partial support for pthreads on Android... You can try using source code and phpize as usual but will fail.

TheDiamondYT1 commented 7 years ago

pthreads can be included in a static PHP binary on Android

PokeyvalGamer commented 7 years ago

But with pecl and phpize missing php-pthreads.lo for make

PokeyvalGamer commented 7 years ago

1 warning and 14 errors generated. make: *** [Makefile:196: php_pthreads.lo] Error 1 ERROR: `make' failed

TheDiamondYT1 commented 7 years ago

@PokeyvalGamer Someone has created a static PocketMine-MP Android binary but it's 32-bit and i need 64-bit, since PocketMine dropped 32-bit support.

Maybe we can do what happens on Ubuntu — install the basic PHP then install extensions seperatly as their own packages. This would allow for greater flexibility and ease of use.

@fornwall @vishalbiswas @Neo-Oli

PokeyvalGamer commented 7 years ago

@TheDiamondYT1 Yes, but I tried to install pthreads with pecl / gcc / make but this gives me the error above you have an idea to install the extentions once the lib created it can be put with the php.ini

TheDiamondYT1 commented 7 years ago

https://packages.ubuntu.com/zesty/php/

look through there and you can see many php extensions

PokeyvalGamer commented 7 years ago

Yes but pthreads is here https://pecl.php.net/package/pthreads

TheDiamondYT1 commented 7 years ago

@PokeyvalGamer pthreads doesn't contain a makefile...

PokeyvalGamer commented 7 years ago

pecl and phpize create the makefile but make give this error : make: *** [Makefile:196: php_pthreads.lo] Error 1 (php-pthreads.lo not found) else make give this error : no makefile found. Stop. @TheDiamondYT1

TheDiamondYT1 commented 7 years ago

@PokeyvalGamer Try compiling pthreads alongside php. When running ./configure in PHP, try including the pthreads directory in that command

PokeyvalGamer commented 7 years ago

with pecl : https://pastebin.com/6m3BNHYu how to run ./configure with php when i run phpize with out pecl in the folder pthreads he failed chmod : Operation not permitted and can't run scripts @TheDiamondYT1

TheDiamondYT1 commented 7 years ago

@PokeyvalGamer You don't actually compile it in Termux... you do it on Linux

ClosetGeek-Git commented 7 years ago

To get it working I downloaded pthreads from https://github.com/krakjoe/pthreads and PHP 7.1.8 source from php.net. You will need to add pthreads to the ext/ folder within the php-7.1.8.tar.xz (note to verify that pthreads is located at ext/pthreads in the tar.xz, NOT ext/pthreads-master). With pthreads in the PHP source tree you can run buildconf to have PHP's configure file remade to include pthreads as an option in ./configure (--enable-pthreads)

You will have to add the new php-7.1.8.tar.xz to a webserver (such as localhost if you have httpd on your localhost) so that termux-packages can fetch it from the build.sh file. You will get 2 errors once you try to build PHP: First is that the hash code of the new php tar.xz doesnt match that in the build.sh file. It will show both the expected hash value and the hash value of the new php tar.xz file in the error, so copy new value to build.sh. Next error will be about pthreads including all of it's header files (such as classes/pool.h) within <>'s and to change to quotes. This is solved by adding pthreads classes dir and src dir to your C_INCLUDE_PATH. Once built it will work - The low end device that I tested it on was able to do 274.344 (274 point 344) threads per seconds when running ./php -f examples/Benchmark.php from pthreads source.

TheDiamondYT1 commented 7 years ago

I'm sure we can do it like it is done on Linux.


  1. Install PHP from APT
  2. Install PHP extension from APT
  3. Jackpot

This way is much more flexible and doesn't require many extensions to be included with the base PHP package.

ClosetGeek-Git commented 7 years ago

@TheDiamondYT1 correct, but the ext needs to be compiled before it can be packaged for apt.

TheDiamondYT1 commented 7 years ago

Obviously, but the current system is 'just compile it with PHP and be done with it'

ClosetGeek-Git commented 7 years ago

@TheDiamondYT1 your walking a path that has frustrated developers for close to a decade. phpize is not cross-compile friendly, which means you can only compile php extensions for android (including pecl) by adding them to the php base source tree. this isn't termux specific. you should forward complaints to #phpinterals

TheDiamondYT1 commented 7 years ago

@ClosetMonkey I once used an Android web server app that let you toggle extensions

ClosetGeek-Git commented 7 years ago

@TheDiamondYT1 yes, but this specific project is for compiling packages. I can send you an .dpkg of the pthreads ext for php for android if you need,

TheDiamondYT1 commented 7 years ago

Someone else compiled PHP 7.2 with pthreads for me.

vaites commented 7 years ago

I think is a waste of time to try to cross compile any PECL extension using the Android SDK on x86 like any other package or PHP itself. These extensions must be compiled on the device because we have all the necessary (C compiler, php-dev package, dev packages for any library...) and PECL is made this way.

We need to fix phpize script and anything else to replace temporary paths and make it work for simple extensions (I tried some patches but don't have time to complete, test and publish it) and then try to compile on the device. Probably the extension will need some patches like many other packages that uses pthreads because of the limited implementation on Android, but done this the extension must compile without problems.

SDRausty commented 7 years ago

@vaites The more we can do on device, the better! Like making https://github.com/termux/termux-app on device is way cool. https://github.com/sdrausty/buildAPKs/issues/3 Can we get docker on device, or do we need docker to make packages (*.deb) on device?

vaites commented 7 years ago

No need to use docker on the device... To compile a PECL extension in any Linux distro you need the PHP header files, a C compiler and the dependencies. We have all now on Termux.

SDRausty commented 7 years ago

@vaites can you supply us with a brief example please. A screenshot is greatly appreciated too. I hope it is not too much to ask. I would like to build and package https://github.com/termux/termux-packages/tree/master/packages/moon-buggy on device; PHP as well.

vaites commented 7 years ago

Of course. I compiled just now the ImageMagick extension:

apt install autoconf pkg-config clang libllvm termux-elf-cleaner imagemagick-dev pcre-dev
wget http://pecl.php.net/get/imagick-3.4.3.tgz
tar xzvf imagick-3.4.3.tgz
cd imagick-3.4.3
phpize
# here I edited _configure_ and replaced `/bin/sh` with `/data/data/com.termux/files/usr/bin/sh`
./configure 
make
make install
termux-elf-cleaner /data/data/com.termux/files/usr/lib/php/imagick.so
# here I added `extension=imagick-3.4.3.tgz. so` to php.ini
php -m | grep imagick

I attached two files: the successful compilation and the phpinfo() output.

screenshot_20170904-235330 screenshot_20170904-235830

vaites commented 7 years ago

As I said, we need to patch php package to fix /bin/sh problem and some other paths. I have some patches done but not enough time to complete. Will send a pull request as soon as I can.

SDRausty commented 7 years ago

screenshot_20170904-183401

After phpsize

$termux-chroot
$cd imagick-3.4.3
$make
.
.
.
Build complete.
Don't forget to run 'make test'.

$

Thank you! screenshot_20170904-183908

"ldconfig Permission denied" keeps creeping up, not just here.

ClosetGeek-Git commented 7 years ago

What libc is being used when compiled on device?

its-pointless commented 7 years ago

bionic libc ... the native one

ClosetGeek-Git commented 7 years ago

So the toolchain on the device has the appropriate Android NDK headers? This is very cool if so

its-pointless commented 7 years ago

yes that is what seperates termux from chroot linux image. everything is using bionic libc.

SDRausty commented 7 years ago

@its-pointless How can I let it see ldconfig? This might resolve lm-sensors too.

its-pointless commented 7 years ago

thats the reason we set LD_LIBRARY_PATH so the linker can see it.

SDRausty commented 7 years ago

@its-pointless where how if you don't mind me asking? termux-chroot doesn't set it; Does it?

its-pointless commented 7 years ago

iv never bothered with php. But when you start termux the shell env LD_LIBRARY_PATH is set to /data/data/com.termux/files/usr/lib. this makes the linker at /system/bin/linker or linker64 to search our libs before the android libs. to add to this search path either the executable searches a specific path or you can do this from shell. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/data/data/com.termux/usr/lib/otherlibpath

SDRausty commented 7 years ago

@its-pointless I enjoyed rust btw.

Online help:     https://termux.com/help
Community forum: https://termux.com/community
IRC channel:     #termux on freenode
Gitter chat:     https://gitter.im/termux/termux
Mailing list:    termux+subscribe@groups.io

Search packages:   pkg search <query>
Install a package: pkg install <package>
Upgrade packages:  pkg upgrade
Learn more:        pkg help
$ $LD_LIBRARY_PATH
bash: /data/data/com.termux/files/usr/lib: Is a directory
$ termux-chroot
$ $LD_LIBRARY_PATH
bash: /data/data/com.termux/files/usr/lib: Is a directory
$
vaites commented 7 years ago

There are extensions that need patches. @fornwall, what's the best way to do this?. I mean, must we provide patches with php-dev package for the extensions? Must we patch phpize script to automate this?.

Suggestions are welcome...

ClosetGeek-Git commented 6 years ago

One suggestion would be to build both threadsafe and non-ts versions of libphp7. Current package is non-ts. Not all sapis can use non-ts builds, and some extensions require it a threadsafe build. Any major distribution offers both.

grigruss commented 5 years ago

I have a problem with compiling imagick. Make fatal error: 'pcre2.h' file not found This included in /data/data/com/termux/files/usr/include/php/ext/pcre/php_pcre.h:27:10:

include "pcre2.h"

How can I fix it?

Grimler91 commented 5 years ago

@grigruss you can install the package that contains the file that it doesn't find.

Header files are found in the -dev packages. Installing pcre2-dev should solve the problem in your case.

grigruss commented 5 years ago

@Grimler91 thank you! It's work!

stale[bot] commented 2 years ago

This issue/PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

AndrewKusov commented 1 year ago

Can you help build a CLI with ZTS support? I tried to add in build.sh PHP package flag --enable-zts, however, the build with this flag fails with errors. TSRM.c: error: undefined symbol: _tsrm_ls_cache

AndrewKusov commented 1 year ago

To get it working I downloaded pthreads from https://github.com/krakjoe/pthreads and PHP 7.1.8 source from php.net. You will need to add pthreads to the ext/ folder within the php-7.1.8.tar.xz (note to verify that pthreads is located at ext/pthreads in the tar.xz, NOT ext/pthreads-master). With pthreads in the PHP source tree you can run buildconf to have PHP's configure file remade to include pthreads as an option in ./configure (--enable-pthreads)

Please tell me if this instruction is working today with PHP 8.2? I can't compile it in a termux package with the --enable-zts flag to connect parallel