2

I built a number of custom PHP extensions under windows 8-10 years ago. I made the move to Ubuntu Linux for all of my web stuff some years ago and find I need to create another custom extension. I'll be doing the development under Ubuntu this time.

I've created a very simple extension (a no-op actually) just to make sure I have the build process working. It's not.

Here is what I have done:

  • Cloned PHP from Git
  • Checked out PHP-5.5
  • Configured with --disable-all --enable-debug --enable-maintainer-zts \
    --prefix=
  • Build PHP
    Success php -i shows:
    Zend Extension Build => API220121212,TS,debug
    PHP Extension Build => API20121212,TS,debug
  • Created ext/a1 for my new, very simple extension
  • Created the basic extension (from Sara Goleman's book)
  • Ran phpize in ext/a1
  • Ran ./configure --enable-a1
  • Ran make
    Build was successful.
    Copied a1.so to the extensions directory
    phpdir/bin/php -dextension=a1.so -v
    Fails. Results in:
    Module compiled with build ID=API20121212,NTS
    PHP compiled with build ID=API20121212,TS,debug

So. Color me confused. According to what I've read, the phpize command is supposed to match the extension build settings to the php build settings.
I've apparently missed something basic here somewhere.

Help will be most appreciated.

1 Answer 1

1

Its hard to say what exactly was going wrong, I can only say that the extension was build using a different config than the php version.

I will describe some reproducible steps how to compile a most basic extension with debug symbols within the PHP source folder. The extension contains no code except of some boilerplate code created by ext_skel. It just describes the compilation process on UNIX. It is a shell script, you might execute it.

#!/bin/sh

# Should work for all PHP5 versions
VERSION="5.6.9"

# Download the PHP source code
wget \
    --continue "http://de2.php.net/get/php-$VERSION.tar.gz/from/this/mirror" \
    -O "php-$VERSION".tar.gz

tar xf "php-$VERSION.tar.gz" && cd "php-$VERSION/ext"

# Create a hello extension from skeletons
./ext_skel --extname="hello"

# Uncomment two lines in ext/hello/config.m4
# Read the comments there and you'll know what I'm doing
sed -ri.original \
    -e 's/(dnl )(PHP_ARG_ENABLE\(hello)/\2/' \
    -e 's/(dnl )(\[  --enable-hello)/\2/' \
    hello/config.m4

# Build PHP and the extension
cd ..
./buildconf --force
./configure \
    --enable-debug --enable-maintainer-zts \
    --enable-hello=shared
make -j

# Test if it is working
sapi/cli/php \
    -dextension=modules/hello.so \
    -r 'var_dump(extension_loaded("hello"));'

You can now start to enter code to ext/hello/hello.c and create your extension. If you want to compile the changes you make just issue make without arguments.

Since we've compiled using --debug we you can now use gdb to debug the C code and explore how PHP internally works. To start a debugging session use:

gdb sapi/cli/php
...
(gdb) break main
(gdb) run -dextension=modules/hello.so some.php

Of course you'll mostly set breakpoints into your extension functions rather than in the php main() function once you've added code to the extension. However, this should show the basic steps to get there.

Have fun! :)

gdb
Sign up to request clarification or add additional context in comments.

6 Comments

Hmm. Black magic ensues, apparently ;-) So, I do that in my extension source dir?
Yes, in the extension source dir. I assume that you have compiled php with --enable-debug in /path/to/php-source before. (This would create the right php-config script). If not, do it.
configure: WARNING: unrecognized options: --enable-debug configure: error: Cannot find php-config. Please use --with-php-config=PATH I have confirmed the path to php-config and tried both with and without the php-config filename.
You are right the enable-debug option is not necessary (and wrong) when configuring the extension. The --with-php-config is important. Where did you build php in debugging mode? (In which folder?)
PHP sources are in /Volumes/Data01/VMShares/PhpDevelopment/php-src-55 and that is where I built PHP. My extension is in /Volumes/Data01/VMShares/PhpDevelopment/php-src-55/ext/a1 and that is where I ran phpize and configure.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.