ZooKernel/Embed/PHP Setup

Do you have a lot of existing PHP code and need to use it as a ZOO Service with the least modifications possible? Then this page is made for you :)

On this page, you will find advice on how to implement your services directly in PHP.

Configure and Install the PHP Embeded library

ZOO Kernel requires a PHP installation that is compiled with the following configure settings: --enable-embed and '--enable-maintainer-zts. If you already have PHP installed on your system, but not with those settings (you can check by looking at a phpinfo for your server, which lists the configure command that was used to build PHP), we recommend installing a fresh and independent PHP library on your system.

Here is a sample configure call to ensure the PHP support on your platform :

./configure' '--prefix=/usr/lib/php5.2.10' \

As you could seen above, there are lot of configure options used. Nevertheless, two configure options are required to get a full PHP support in your ZooKernel : --enable-embed and '--enable-maintainer-zts. You should also note that the php library will be installed in the /usr/lib/php5.2.10 directory, as we need a well separated installation of php to not interfere with your possibly already installed PHP version.

Once you configure script ends with success, you're now ready to compile and install the PHP embed library, using the following commands :

make test
make install

Verify PHP Embed Install

Sample C Script

The following C script loads and runs a PHP script. Save the file as test_phpembed.c

  * Filename : test_phpembed.c
#include <stdio.h>
#include <sapi/embed/php_embed.h>
#include <zend_stream.h>

int main(int argc,char*argv[]){
  zend_file_handle script;
    fprintf(stderr,"Usage: embed filename.php <arguments>\n");
    return -1;

    fprintf(stderr,"Unable to open : %s\n",argv[1]);
    return -1;

    php_execute_script(&script TSRMLS_CC);

  return 0;

Compile the code snippet

Now that you have the file test_phpembed.c you must compile it using the following commands :

gcc -o test_phpembeded.o test_phpembeded.c -c $(/usr/lib/php5.2.10/bin/php-config --includes)
gcc -o test_phpembeded test_phpembeded.o $(/usr/lib/php5.2.10/bin/php-config --ldflags) $(/usr/lib/php5.2.10/bin/php-config --libs) -L /usr/lib/php5.2.10/lib/ -lphp5

The above commands should produce the test_phpembeded.o file and the test_phpembeded program with no errors.

Run the code snippet

The last step to get your PHP embeded in your C program is to write a small PHP code by:

cat > info.php <<EOF
<? phpinfo(); ?>

No we can run the test_phpembeded program to see if it's able to load and run the PHP script called info.php:

LD_LIBRARY_PATH="/usr/lib/php5.2.10/lib/" ./test_phpembeded /var/www/localhost/htdocs/info.php | less

The output from phpinfo() should be returned at the commandline if successful.

Note that we have to set the LD_LIBRARY_PATH at runtime as we didn't install the php embed library in a standard way (not in the standard search path - /usr/lib or /usr/local/lib- to ensure that we don't interfere with your already installed php library). Nevertheless, when ZooKernel will be compiled you only have to run it once, so you could use a small batch file including this LD_LIBRARY_PATH and other required parameters when you launch your ZooKernel instance (note that firefox does something like that also).


Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png