termux-packages icon indicating copy to clipboard operation
termux-packages copied to clipboard

Compile PHP with pthreads

Open TheDiamondYT1 opened this issue 7 years ago • 53 comments

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

TheDiamondYT1 avatar Apr 02 '17 09:04 TheDiamondYT1

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

vaites avatar Apr 15 '17 17:04 vaites

The software I'm trying to run requires pthreads

TheDiamondYT1 avatar Apr 18 '17 23:04 TheDiamondYT1

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

robertvalik avatar Jul 05 '17 19:07 robertvalik

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

robertvalik avatar Jul 06 '17 06:07 robertvalik

How to install pthreads ?

PokeyvalGamer avatar Aug 13 '17 00:08 PokeyvalGamer

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.

vaites avatar Aug 13 '17 09:08 vaites

pthreads can be included in a static PHP binary on Android

TheDiamondYT1 avatar Aug 13 '17 09:08 TheDiamondYT1

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

PokeyvalGamer avatar Aug 13 '17 10:08 PokeyvalGamer

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

PokeyvalGamer avatar Aug 13 '17 10:08 PokeyvalGamer

@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

TheDiamondYT1 avatar Aug 15 '17 21:08 TheDiamondYT1

@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

PokeyvalGamer avatar Aug 15 '17 21:08 PokeyvalGamer

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

look through there and you can see many php extensions

TheDiamondYT1 avatar Aug 15 '17 21:08 TheDiamondYT1

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

PokeyvalGamer avatar Aug 15 '17 21:08 PokeyvalGamer

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

TheDiamondYT1 avatar Aug 15 '17 21:08 TheDiamondYT1

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

PokeyvalGamer avatar Aug 15 '17 22:08 PokeyvalGamer

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

TheDiamondYT1 avatar Aug 15 '17 22:08 TheDiamondYT1

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

PokeyvalGamer avatar Aug 16 '17 09:08 PokeyvalGamer

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

TheDiamondYT1 avatar Aug 16 '17 11:08 TheDiamondYT1

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.

ClosetGeek-Git avatar Aug 30 '17 08:08 ClosetGeek-Git

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.

TheDiamondYT1 avatar Sep 01 '17 19:09 TheDiamondYT1

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

ClosetGeek-Git avatar Sep 03 '17 04:09 ClosetGeek-Git

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

TheDiamondYT1 avatar Sep 03 '17 10:09 TheDiamondYT1

@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

ClosetGeek-Git avatar Sep 04 '17 15:09 ClosetGeek-Git

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

TheDiamondYT1 avatar Sep 04 '17 15:09 TheDiamondYT1

@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,

ClosetGeek-Git avatar Sep 04 '17 16:09 ClosetGeek-Git

Someone else compiled PHP 7.2 with pthreads for me.

TheDiamondYT1 avatar Sep 04 '17 16:09 TheDiamondYT1

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.

vaites avatar Sep 04 '17 21:09 vaites

@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?

SDRausty avatar Sep 04 '17 21:09 SDRausty

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.

vaites avatar Sep 04 '17 21:09 vaites

@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.

SDRausty avatar Sep 04 '17 21:09 SDRausty