Search code examples
phpc++php-extension

How to set build optimization level when building PHP extension with phpize


I am writing a PHP extension in C++ using this sample.

In Visual Studio project 'properties -> c/c++ -> optimization' I can set speed optimization (O2) or Full optimization(Ox).

As I imagine, in linux after running:

phpize 
./configure

Any suggestions where the optimization parameters should be set?


Solution

  • You can probably (I did not try, but this is how it usually goes) add additional compiler flags to the configure script when you run it. Export the flags you require first and rerun the regular compilation steps:

    export CFLAGS="-O2"
    # Just to make sure that the old files are removed:
    phpize --clean
    phpize
    ./configure
    make
    

    Instead of -O2 you can obviously use an other optimization level as well.