├── php_rlyeh.h ├── .gitignore ├── config.m4 ├── php_rlyeh.c └── README.markdown /php_rlyeh.h: -------------------------------------------------------------------------------- 1 | #define PHP_RLYEH_EXTNAME "rlyeh" 2 | #define PHP_RLYEH_VERSION "0.01" 3 | 4 | PHP_FUNCTION(cthulhu); 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | .deps 3 | .libs 4 | Makefile 5 | Makefile.fragments 6 | Makefile.global 7 | Makefile.objects 8 | acinclude.m4 9 | aclocal.m4 10 | autom4te.cache 11 | build 12 | config.guess 13 | config.h 14 | config.h.in 15 | config.log 16 | config.nice 17 | config.status 18 | config.sub 19 | configure 20 | configure.in 21 | install-sh 22 | libtool 23 | ltmain.sh 24 | missing 25 | mkinstalldirs 26 | modules 27 | *.lo 28 | *.la 29 | run-tests.php 30 | -------------------------------------------------------------------------------- /config.m4: -------------------------------------------------------------------------------- 1 | dnl lines starting with "dnl" are comments 2 | 3 | PHP_ARG_ENABLE(rlyeh, whether to enable Rlyeh extension, [ --enable-rlyeh Enable Rlyeh extension]) 4 | 5 | if test "$PHP_RLYEH" != "no"; then 6 | 7 | dnl this defines the extension 8 | PHP_NEW_EXTENSION(rlyeh, php_rlyeh.c, $ext_shared) 9 | 10 | dnl this is boilerplate to make the extension work on OS X 11 | case $build_os in 12 | darwin1*.*.*) 13 | AC_MSG_CHECKING([whether to compile for recent osx architectures]) 14 | CFLAGS="$CFLAGS -arch i386 -arch x86_64 -mmacosx-version-min=10.5" 15 | AC_MSG_RESULT([yes]) 16 | ;; 17 | darwin*) 18 | AC_MSG_CHECKING([whether to compile for every osx architecture ever]) 19 | CFLAGS="$CFLAGS -arch i386 -arch x86_64 -arch ppc -arch ppc64" 20 | AC_MSG_RESULT([yes]) 21 | ;; 22 | esac 23 | 24 | fi 25 | -------------------------------------------------------------------------------- /php_rlyeh.c: -------------------------------------------------------------------------------- 1 | // include PHP API 2 | #include 3 | 4 | // header file we'll create below 5 | #include "php_rlyeh.h" 6 | 7 | // define the function(s) we want to add 8 | zend_function_entry rlyeh_functions[] = { 9 | PHP_FE(cthulhu, NULL) 10 | { NULL, NULL, NULL } 11 | }; 12 | 13 | // "rlyeh_functions" refers to the struct defined above 14 | // we'll be filling in more of this later: you can use this to specify 15 | // globals, php.ini info, startup and teardown functions, etc. 16 | zend_module_entry rlyeh_module_entry = { 17 | STANDARD_MODULE_HEADER, 18 | PHP_RLYEH_EXTNAME, 19 | rlyeh_functions, 20 | NULL, 21 | NULL, 22 | NULL, 23 | NULL, 24 | NULL, 25 | PHP_RLYEH_VERSION, 26 | STANDARD_MODULE_PROPERTIES 27 | }; 28 | 29 | // install module 30 | ZEND_GET_MODULE(rlyeh) 31 | 32 | // actual non-template code! 33 | PHP_FUNCTION(cthulhu) { 34 | // php_printf is PHP's version of printf, it's essentially "echo" from C 35 | php_printf("In his house at R'lyeh dead Cthulhu waits dreaming.\n"); 36 | } 37 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | PHP Extensions Made Eldritch: Code Samples 2 | ------------------------------------------ 3 | 4 | The code in this repository accompanies the PHP Extensions Made Eldritch tutorial, available at: 5 | 6 | * [Installing PHP](http://www.snailinaturtleneck.com/blog/2011/08/11/php-extensions-made-eldrich-installing-php/) 7 | * [Hello, World!](http://www.snailinaturtleneck.com/blog/2011/08/11/php-extensions-made-eldrich-hello-world/) 8 | * [PHP Variables](http://www.snailinaturtleneck.com/blog/2011/08/11/php-extensions-made-eldrich-php-variables/) 9 | * [Classes](http://www.snailinaturtleneck.com/blog/2011/08/11/php-extensions-made-eldrich-classes/) 10 | 11 | If you don't want to copy/paste all of the code, you can clone this repo and check out sections as you go. 12 | 13 |
14 | $ git clone git://github.com/kchodorow/rlyeh.git
15 | 
16 | 17 | Part 2 of the tutorial (Hello, world!) is on the master branch. Stating in part 3, each "unit" has a branch: <branchname> at the beginning. You can checkout this branch if you want to see the code example in context. 18 | 19 | For example, if you see branch: oop, you'd do: 20 | 21 |
22 | $ git checkout -b oop origin/oop
23 | 
24 | 25 | Then you can compare what you're doing to the example. 26 | --------------------------------------------------------------------------------