# PHP for embedded device: reduce size

- Thread: https://externals.io/message/51474
- Original archive: https://news-web.php.net/php.internals/51474
- Started by Martin Herrman on 2011-02-19T18:24:35+00:00
- Messages: 16
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #51474 — Martin Herrman — 2011-02-19T18:24:35+00:00

URL: https://externals.io/message/51474#51474

All,

I have cross-compiled php-cgi for a MIPS device (mediaplayer), but the
binary is quite large, more than 3MB. I'm using:

./configure --prefix=../result/php-5.3.5 --host=i686-pc-linux-gnu
--target=mipsel-linux-gnu --build=mipsel-linux-gnu --enable-cgi
--disable-all --without-pear --with-config-file-path=/etc/

Which options do I have to reduce size of the binary? E.g. can I
remove the zend engine?

Thanks in advance,

Martin

---

## #51475 — Alexey Zakhlestin — 2011-02-20T10:07:41+00:00

URL: https://externals.io/message/51474#51475 · In reply to: #51474

> All,
>
> I have cross-compiled php-cgi for a MIPS device (mediaplayer), but the
> binary is quite large, more than 3MB. I'm using:
>
> ./configure --prefix=../result/php-5.3.5 --host=i686-pc-linux-gnu
> --target=mipsel-linux-gnu --build=mipsel-linux-gnu --enable-cgi
> --disable-all --without-pear --with-config-file-path=/etc/
>
> Which options do I have to reduce size of the binary? E.g. can I
> remove the zend engine?

what do you mean by "remove the zend engine"?
zend engine is the core, upon which php is built.

-- 
Alexey Zakhlestin, http://twitter.com/jimi_dini
http://www.milkfarmsoft.com/

---

## #51476 — Martin Herrman — 2011-02-20T10:09:55+00:00

URL: https://externals.io/message/51474#51476 · In reply to: #51475

2011/2/20 Alexey Zakhlestin <indeyets@gmail.com>:

> what do you mean by "remove the zend engine"?
> zend engine is the core, upon which php is built.

Ah, that explains a lot :-) I thought zend engine is an additional
engine for performance reasons..

Is there any other way to decrease binary size? (workaround is to put
php-cgi on external storage)

---

## #51477 — Patrick E. — 2011-02-20T13:06:00+00:00

URL: https://externals.io/message/51474#51477 · In reply to: #51476

> Is there any other way to decrease binary size? (workaround is to put
> php-cgi on external storage)

php-cgi 5.2.x = ~2.4mb "./configure" without :
...
--without-iconv \
--without-pear  \
--without-gd \
--disable-bcmath  \
--disable-libxml --disable-dom --disable-simplexml --disable-xml
--disable-xmlreader --disable-xmlwriter --without-pear  \
--with-sqlite \
--without-pdo-sqlite



-- 
freundliche Grüsse / best Regards,
Patrick C. Engel

---

## #51478 — Reindl Harald — 2011-02-20T13:10:58+00:00

URL: https://externals.io/message/51474#51478 · In reply to: #51476

Am 20.02.2011 11:09, schrieb Martin Herrman:
> 2011/2/20 Alexey Zakhlestin <indeyets@gmail.com>:
> 
> > […]
> 
> Ah, that explains a lot :-) I thought zend engine is an additional
> engine for performance reasons..
> 
> Is there any other way to decrease binary size? (workaround is to put
> php-cgi on external storage)

./configure --help

disable all things you do not need, but be careful as long you
do not know what you doing since "I thought zend engine is an
additional engine" sounds like you are missing basics

---

## #51479 — Martin Herrman — 2011-02-20T14:52:59+00:00

URL: https://externals.io/message/51474#51479 · In reply to: #51477

2011/2/20 Patrick E. <zenobic@googlemail.com>:

> php-cgi 5.2.x = ~2.4mb "./configure" without :
> ...
> --without-iconv \
> --without-pear  \
> --without-gd \
> --disable-bcmath  \
> --disable-libxml --disable-dom --disable-simplexml --disable-xml
> --disable-xmlreader --disable-xmlwriter --without-pear  \
> --with-sqlite \
> --without-pdo-sqlite

For latest 5.3.x it still results in a 3+ MB php-cgi binary.

---

## #51480 — Martin Herrman — 2011-02-20T14:55:07+00:00

URL: https://externals.io/message/51474#51480 · In reply to: #51478

2011/2/20 Reindl Harald <h.reindl@thelounge.net>:

> ./configure --help
>
> disable all things you do not need, but be careful as long you
> do not know what you doing since "I thought zend engine is an
> additional engine" sounds like you are missing basics

I'll go through the list of options again and disable everything
possible. I am aware of the fact that you must think that I'm a noob,
which is partly true. I do have some PHP programming experience and
sometimes tried to use a function that was not available because it
was not compiled in. But I just tried to have some really basic
functionality included, I can rebuild again when needed. But still:
thanks for the warning :-)

---

## #51481 — Lytochkin Boris — 2011-02-20T15:00:13+00:00

URL: https://externals.io/message/51474#51481 · In reply to: #51474

> All,
>
> I have cross-compiled php-cgi for a MIPS device (mediaplayer), but the
> binary is quite large, more than 3MB. I'm using:
>
> ./configure --prefix=../result/php-5.3.5 --host=i686-pc-linux-gnu
> --target=mipsel-linux-gnu --build=mipsel-linux-gnu --enable-cgi
> --disable-all --without-pear --with-config-file-path=/etc/
>
> Which options do I have to reduce size of the binary?

Check Makefile and correct cc's -O setting to -Os before compiling. Is
your binary stripped?

-- 
Boris

---

## #51482 — Reindl Harald — 2011-02-20T15:01:18+00:00

URL: https://externals.io/message/51474#51482 · In reply to: #51479

Am 20.02.2011 15:52, schrieb Martin Herrman:
> 2011/2/20 Patrick E. <zenobic@googlemail.com>:
> 
> > […]
> 
> For latest 5.3.x it still results in a 3+ MB php-cgi binary.

There are some more swicthes
--disable-all   Disable all extensions which are enabled by default

What about "--disable-all" followed by "--enable-feature" for all
you want to have?

The follwoing are not needed in most cases
--disable-ipv6
--disable-posix
--disable-phar
--disable-json
__________________________________

  --disable-ipv6          Disable IPv6 support
  --disable-libxml        Disable LIBXML support
  --disable-ctype         Disable ctype functions
  --disable-inifile       DBA: INI support (bundled)
  --disable-flatfile      DBA: FlatFile support (bundled)
  --disable-dom           Disable DOM support
  --disable-fileinfo      Disable fileinfo support
  --disable-filter        Disable input filter support
  --disable-hash          Disable hash support
  --disable-json          Disable JavaScript Object Serialization support
  --disable-mbregex       MBSTRING: Disable multibyte regex support
  --disable-pdo           Disable PHP Data Objects support
  --disable-phar          Disable phar support
  --disable-posix         Disable POSIX-like functions
  --disable-session       Disable session support
  --disable-simplexml     Disable SimpleXML support
  --disable-tokenizer     Disable tokenizer support
  --disable-xml           Disable XML support
  --disable-xmlreader     Disable XMLReader support
  --disable-xmlwriter     Disable XMLWriter support

---

## #51483 — Martin Herrman — 2011-02-20T15:42:28+00:00

URL: https://externals.io/message/51474#51483 · In reply to: #51482

2011/2/20 Reindl Harald <h.reindl@thelounge.net>:

> There are some more swicthes
> --disable-all   Disable all extensions which are enabled by default
>
> What about "--disable-all" followed by "--enable-feature" for all
> you want to have?
>
> The follwoing are not needed in most cases
> --disable-ipv6
> --disable-posix
> --disable-phar
> --disable-json
> __________________________________
>
>  --disable-ipv6          Disable IPv6 support
>  --disable-libxml        Disable LIBXML support
>  --disable-ctype         Disable ctype functions
>  --disable-inifile       DBA: INI support (bundled)
>  --disable-flatfile      DBA: FlatFile support (bundled)
>  --disable-dom           Disable DOM support
>  --disable-fileinfo      Disable fileinfo support
>  --disable-filter        Disable input filter support
>  --disable-hash          Disable hash support
>  --disable-json          Disable JavaScript Object Serialization support
>  --disable-mbregex       MBSTRING: Disable multibyte regex support
>  --disable-pdo           Disable PHP Data Objects support
>  --disable-phar          Disable phar support
>  --disable-posix         Disable POSIX-like functions
>  --disable-session       Disable session support
>  --disable-simplexml     Disable SimpleXML support
>  --disable-tokenizer     Disable tokenizer support
>  --disable-xml           Disable XML support
>  --disable-xmlreader     Disable XMLReader support
>  --disable-xmlwriter     Disable XMLWriter support

I already had --disabled-all. I have now tested with -Os instead of
-O2 which results in a 2.8MB executable. So that helps a bit :-)

---

## #51484 — Rasmus Lerdorf — 2011-02-20T15:50:44+00:00

URL: https://externals.io/message/51474#51484 · In reply to: #51483

> 2011/2/20 Reindl Harald <h.reindl@thelounge.net>:
> 
> > […]
> 
> I already had --disabled-all. I have now tested with -Os instead of
> -O2 which results in a 2.8MB executable. So that helps a bit :-)

2.8M? My php binary with just about everything compiled in is around
1MB. Do this:

file php

See how it says "not stripped" ?

That means you have left all the debugging symbols in.  Now do this:

strip php

Then check the file size.

Magic!

-Rasmus

---

## #51485 — Ferenc Kovacs — 2011-02-20T15:52:06+00:00

URL: https://externals.io/message/51474#51485 · In reply to: #51482

On Sun, Feb 20, 2011 at 4:01 PM, Reindl Harald <h.reindl@thelounge.net>wrote:

>
>
> Am 20.02.2011 15:52, schrieb Martin Herrman:
> > […]
>
> There are some more swicthes
> --disable-all   Disable all extensions which are enabled by default
>
> What about "--disable-all" followed by "--enable-feature" for all
> you want to have?
>
> The follwoing are not needed in most cases
> --disable-ipv6
> --disable-posix
> --disable-phar
> --disable-json
> __________________________________
>
>  --disable-ipv6          Disable IPv6 support
>  --disable-libxml        Disable LIBXML support
>  --disable-ctype         Disable ctype functions
>  --disable-inifile       DBA: INI support (bundled)
>  --disable-flatfile      DBA: FlatFile support (bundled)
>  --disable-dom           Disable DOM support
>  --disable-fileinfo      Disable fileinfo support
>  --disable-filter        Disable input filter support
>  --disable-hash          Disable hash support
>  --disable-json          Disable JavaScript Object Serialization support
>  --disable-mbregex       MBSTRING: Disable multibyte regex support
>  --disable-pdo           Disable PHP Data Objects support
>  --disable-phar          Disable phar support
>  --disable-posix         Disable POSIX-like functions
>  --disable-session       Disable session support
>  --disable-simplexml     Disable SimpleXML support
>  --disable-tokenizer     Disable tokenizer support
>  --disable-xml           Disable XML support
>  --disable-xmlreader     Disable XMLReader support
>  --disable-xmlwriter     Disable XMLWriter support
>
>
did you bother to read his first email?
he exactly did that: --disable-all and --enable-cgi

Tyrael

---

## #51486 — Daniel Brown — 2011-02-20T15:53:07+00:00

URL: https://externals.io/message/51474#51486 · In reply to: #51483

>
> I already had --disabled-all. I have now tested with -Os instead of
> -O2 which results in a 2.8MB executable. So that helps a bit :-)

    Try running `strip` on there to take out the excess symbols.

-- 
</Daniel P. Brown>
Network Infrastructure Manager
Documentation, Webmaster Teams
http://www.php.net/

---

## #51487 — jvlad — 2011-02-20T16:10:19+00:00

URL: https://externals.io/message/51474#51487 · In reply to: #51474

> All,
>
> I have cross-compiled php-cgi for a MIPS device (mediaplayer), but the
> binary is quite large, more than 3MB. I'm using:
>
> ./configure --prefix=../result/php-5.3.5 --host=i686-pc-linux-gnu
> --target=mipsel-linux-gnu --build=mipsel-linux-gnu --enable-cgi
> --disable-all --without-pear --with-config-file-path=/etc/
>
> Which options do I have to reduce size of the binary? E.g. can I
> remove the zend engine?

you may want to re-generate zend_vm_execute.h
php zend_vm_gen.php --without-specializer
It will save ~300k.

also you may want to try to remove Reflection, SPL and Date extensions and 
optimize for size: -O1
instead of performance (-O2)
Don't forget to strip off debug info from the binary.

regards,
j

---

## #51488 — Martin Herrman — 2011-02-20T16:17:17+00:00

URL: https://externals.io/message/51474#51488 · In reply to: #51486

2011/2/20 Daniel Brown <danbrown@php.net>:
> 
> > […]
>
>    Try running `strip` on there to take out the excess symbols.

This is my cross-compile script for -O2:

#!/bin/sh

# Set variables
export CFLAGS="-EL -O2"
export CXXFLAGS="-EL -O2"
export CC="/opt/Sourcery_G++_Lite/bin/mips-linux-gnu-gcc"
export CXX="/opt/Sourcery_G++_Lite/bin/mips-linux-gnu-g++"
export PATH=/opt/Sourcery_G++_Lite/bin:$PATH
export AR="/opt/Sourcery_G++_Lite/bin/mips-linux-gnu-ar"
export LDFLAGS=" -s -Xlinker -rpath /lib -Xlinker -rpath-link
/opt/Sourcery_G++_Lite/lib/gcc/mips-linux-gnu/4.3.3/el"
export STRIP="/opt/Sourcery_G++_Lite/bin/mips-linux-gnu-strip"
export RANLIB="/opt/Sourcery_G++_Lite/bin/mips-linux-gnu-ranlib"
export AS="/opt/Sourcery_G++_Lite/bin/mips-linux-gnu-as"
export LD="/opt/Sourcery_G++_Lite/bin/mips-linux-gnu-ld"

# Cleanup previous compilations
rm -rf /home/martin/result/php-5.3.5
rm -rf /home/martin/work/php*

# Download source and configure, compile, install
cd /home/martin/work
wget http://nl.php.net/get/php-5.3.5.tar.gz/from/this/mirror -O php-5.3.5.tar.gz
tar -zxvf php-5.3.5.tar.gz
cd php-5.3.5
#./configure --help
./configure --prefix=/home/martin/result/php-5.3.5
--host=i686-pc-linux-gnu --target=mipsel-linux-gnu
--build=mipsel-linux-gnu --enable-cgi --disable-all --without-pear
make
make install

This is the result:
martin@martindesktop ~/ $ ls -ltr result/php-5.3.5/bin/php-cgi
-rwxr-xr-x 1 martin users 3142772 Feb 20 16:58 result/php-5.3.5/bin/php-cgi
martin@martindesktop ~/ $ file result/php-5.3.5/bin/php-cgi
result/php-5.3.5/bin/php-cgi: ELF 32-bit LSB executable, MIPS, MIPS32
rel2 version 1, dynamically linked (uses shared libs), for GNU/Linux
2.6.12, with unknown capability 0xf41 = 0x756e6700, with unknown
capability 0x70100 = 0x1040000, stripped
martin@martindesktop ~/ $
/opt/Sourcery_G++_Lite/bin/mips-linux-gnu-strip
result/php-5.3.5/bin/php-cgi
martin@martindesktop ~/ $ file result/php-5.3.5/bin/php-cgi
result/php-5.3.5/bin/php-cgi: ELF 32-bit LSB executable, MIPS, MIPS32
rel2 version 1 (SYSV), dynamically linked (uses shared libs), for
GNU/Linux 2.6.12, with unknown capability 0xf41 = 0x756e6700, with
unknown capability 0x70100 = 0x1040000, stripped
martin@martindesktop ~/ $ ls -ltr result/php-5.3.5/bin/php-cgi
-rwxr-xr-x 1 martin users 3142772 Feb 20 17:07 result/php-5.3.5/bin/php-cgi
martin@martindesktop ~/ $

Now for -Os:

martin@martindesktop ~/ $ ls -ltr result/php-5.3.5/bin/php-cgi
-rwxr-xr-x 1 martin users 2813508 Feb 20 17:10 result/php-5.3.5/bin/php-cgi
martin@martindesktop ~/ $ file result/php-5.3.5/bin/php-cgi
result/php-5.3.5/bin/php-cgi: ELF 32-bit LSB executable, MIPS, MIPS32
rel2 version 1, dynamically linked (uses shared libs), for GNU/Linux
2.6.12, with unknown capability 0xf41 = 0x756e6700, with unknown
capability 0x70100 = 0x1040000, stripped
martin@martindesktop ~/ $
/opt/Sourcery_G++_Lite/bin/mips-linux-gnu-strip
result/php-5.3.5/bin/php-cgi
martin@martindesktop ~/ $ ls -ltr result/php-5.3.5/bin/php-cgi
-rwxr-xr-x 1 martin users 2813508 Feb 20 17:16 result/php-5.3.5/bin/php-cgi
martin@martindesktop ~/ $ file result/php-5.3.5/bin/php-cgi
result/php-5.3.5/bin/php-cgi: ELF 32-bit LSB executable, MIPS, MIPS32
rel2 version 1 (SYSV), dynamically linked (uses shared libs), for
GNU/Linux 2.6.12, with unknown capability 0xf41 = 0x756e6700, with
unknown capability 0x70100 = 0x1040000, stripped
martin@martindesktop ~/ $

---

## #51494 — Andi Gutmans — 2011-02-22T04:21:29+00:00

URL: https://externals.io/message/51474#51494 · In reply to: #51474

HI Martin,

Is it only file size you worry about or also memory footprint? I assume it'd also be the latter.
If so, we can share a patch we've worked on which could allow you to reduce the memory footprint at compile time somewhat more (on the expense of performance, ...).
We were going to send it out for review anyway so this could be it :)

Andi

-----Original Message-----
From: martin.herrman@gmail.com [mailto:martin.herrman@gmail.com] On Behalf Of Martin Herrman
Sent: Saturday, February 19, 2011 10:25 AM
To: internals@lists.php.net
Subject: [PHP-DEV] PHP for embedded device: reduce size

All,

I have cross-compiled php-cgi for a MIPS device (mediaplayer), but the binary is quite large, more than 3MB. I'm using:

./configure --prefix=../result/php-5.3.5 --host=i686-pc-linux-gnu --target=mipsel-linux-gnu --build=mipsel-linux-gnu --enable-cgi --disable-all --without-pear --with-config-file-path=/etc/

Which options do I have to reduce size of the binary? E.g. can I remove the zend engine?

Thanks in advance,

Martin
