Jump to content

Creating an extension with Zend/PHP

- - - - -

  • Please log in to reply
2 replies to this topic

#1
Fighter

Fighter

    Newbie

  • Members
  • PipPip
  • 28 posts
I have purchased a book on Zend framework and had looked in to the hooks in C and what you can do with them, I have successfully created a PHP Zend extension (attached if you want to look) which will run under PHP embedded.. but it will not run as an extension.

How can I hook it into the PHP engine, especially the part to configure and add it as a shared object? The book hardly gets into any of that.

My addon: Private Paste - Pastie

#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
1) Place into /ext/ folder, testplugin.c as you are invoking that in your code.

It should be in the devel docs somewhere, but just create a config.m4
PHP_ARG_ENABLE(testaddon, whether to enable Fighter's testaddon support,
[ --enable-testaddon I am displayed within ./configure --help..])

if test "$PHP_TESTADDON" = "yes"; then
  AC_DEFINE(TESTADDON, 1, [Whether you have testaddon])
  PHP_NEW_EXTENSION(testaddon, testaddon.c, $ext_shared)
fi
Important: note the shared library name.

I am not sure if this will run, I have done this from memory, refer to the docs for dl() once enabled in per-dir settings
dl('testaddon.so');
__MAIN__();
you may want to create a platform wrapper,mind the constants

handle platforms
function _dl($n) {
  return extension_loaded($n) 
    || dl(
    ((PHP_SHLIB_SUFFIX === 'dll') 
    ? 'php_' 
    : '') 
    . ($f ? $f : $n) . '.' . PHP_SHLIB_SUFFIX);
}

Hook library of course
__MAIN__();
This is really jogging my memory, find the developer docs and we can both debug this together if need be. [noparse]:)[/noparse]

Edited by Alexander, 06 January 2011 - 11:40 PM.
updated config.m4

Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#3
Fighter

Fighter

    Newbie

  • Members
  • PipPip
  • 28 posts
I managed to set up its own php.ini section and simple installer in repositories, thank you for setting me on the right track Alex.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users