| 1 | = ZooKernel/Embed/PHP description page = |
| 2 | |
| 3 | You get lot of allready existing php code and need to use this code with the less modifications possible ? Then this page was made for you :) |
| 4 | |
| 5 | On this page you will find everything you have to know to be able to implement your services directly in PHP. |
| 6 | |
| 7 | == Configure and Install PHP Embed library == |
| 8 | |
| 9 | First thing you have to get is a fresh and independant php library installed on your system. |
| 10 | |
| 11 | Here is a sample configure call to ensure to be able to use the PHP support on your platform : |
| 12 | |
| 13 | {{{ |
| 14 | #!sh |
| 15 | ./configure' '--prefix=/usr/lib/php5.2.10' \ |
| 16 | '--host=i686-pc-linux-gnu'\ |
| 17 | '--mandir=/usr/lib/php5.2.10/man'\ |
| 18 | '--infodir=/usr/lib/php5.2.10/info'\ |
| 19 | '--sysconfdir=/etc'\ |
| 20 | '--cache-file=./config.cache'\ |
| 21 | '--with-pcre-regex=/usr'\ |
| 22 | '--enable-maintainer-zts'\ |
| 23 | '--with-config-file-path=/etc/php/apache2-php5.2.10'\ |
| 24 | '--with-config-file-scan-dir=/etc/php/apache2-php5.2.10/ext-active'\ |
| 25 | '--without-pear'\ |
| 26 | '--disable-bcmath'\ |
| 27 | '--with-bz2'\ |
| 28 | '--disable-calendar'\ |
| 29 | '--with-curl'\ |
| 30 | '--without-curlwrappers'\ |
| 31 | '--disable-dbase'\ |
| 32 | '--enable-exif'\ |
| 33 | '--without-fbsql'\ |
| 34 | '--without-fdftk'\ |
| 35 | '--disable-filter'\ |
| 36 | '--enable-ftp'\ |
| 37 | '--with-gettext'\ |
| 38 | '--without-gmp'\ |
| 39 | '--disable-hash'\ |
| 40 | '--without-kerberos'\ |
| 41 | '--enable-mbstring'\ |
| 42 | '--with-mcrypt'\ |
| 43 | '--without-mhash'\ |
| 44 | '--without-msql'\ |
| 45 | '--without-mssql'\ |
| 46 | '--with-ncurses'\ |
| 47 | '--with-openssl'\ |
| 48 | '--with-openssl-dir=/usr'\ |
| 49 | '--disable-pcntl'\ |
| 50 | '--disable-pdo'\ |
| 51 | '--with-pgsql'\ |
| 52 | '--disable-posix'\ |
| 53 | '--without-pspell'\ |
| 54 | '--without-recode'\ |
| 55 | '--disable-shmop'\ |
| 56 | '--without-snmp'\ |
| 57 | '--enable-soap'\ |
| 58 | '--enable-sockets'\ |
| 59 | '--without-sybase'\ |
| 60 | '--without-sybase-ct'\ |
| 61 | '--disable-sysvmsg'\ |
| 62 | '--disable-sysvsem'\ |
| 63 | '--disable-sysvshm'\ |
| 64 | '--without-tidy'\ |
| 65 | '--enable-wddx'\ |
| 66 | '--with-xmlrpc'\ |
| 67 | '--with-xsl'\ |
| 68 | '--enable-zip'\ |
| 69 | '--with-zlib'\ |
| 70 | '--disable-debug'\ |
| 71 | '--enable-dba'\ |
| 72 | '--without-cdb'\ |
| 73 | '--with-db4'\ |
| 74 | '--disable-flatfile'\ |
| 75 | '--with-gdbm'\ |
| 76 | '--disable-inifile'\ |
| 77 | '--without-qdbm'\ |
| 78 | '--with-freetype-dir=/usr'\ |
| 79 | '--with-t1lib=/usr'\ |
| 80 | '--disable-gd-jis-conv'\ |
| 81 | '--with-jpeg-dir=/usr'\ |
| 82 | '--with-png-dir=/usr'\ |
| 83 | '--with-xpm-dir=/usr'\ |
| 84 | '--with-gd'\ |
| 85 | '--without-mysqli'\ |
| 86 | '--with-readline'\ |
| 87 | '--without-libedit'\ |
| 88 | '--without-mm'\ |
| 89 | '--with-sqlite=/usr'\ |
| 90 | '--enable-sqlite-utf8'\ |
| 91 | '--with-pic'\ |
| 92 | '--enable-embed' |
| 93 | }}} |
| 94 | |
| 95 | As you could seen above, there are lot of configure options used. Lots options are not required. 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 sperated installation of php to not interfere with your possibly allready installed PHP version. |
| 96 | |
| 97 | Once your configure script end with success, you're now ready to compile and install the php embed library, using the following commands : |
| 98 | |
| 99 | {{{ |
| 100 | #!sh |
| 101 | make |
| 102 | make test |
| 103 | make install |
| 104 | }}} |
| 105 | |
| 106 | == Simple PHP scripts loader == |
| 107 | |
| 108 | Here is the simplest code snipest ever shared. It was provided here as a sample to load and run php script from a C program : |
| 109 | |
| 110 | {{{ |
| 111 | #!c |
| 112 | /** |
| 113 | * Filename : test_phpembed.c |
| 114 | */ |
| 115 | #include <stdio.h> |
| 116 | #include <sapi/embed/php_embed.h> |
| 117 | #include <zend_stream.h> |
| 118 | |
| 119 | int main(int argc,char*argv[]){ |
| 120 | zend_file_handle script; |
| 121 | if(argc<=1){ |
| 122 | fprintf(stderr,"Usage: embed filename.php <arguments>\n"); |
| 123 | return -1; |
| 124 | } |
| 125 | |
| 126 | script.type=ZEND_HANDLE_FP; |
| 127 | script.filename=argv[1]; |
| 128 | script.opened_path=NULL; |
| 129 | script.free_filename=0; |
| 130 | if(!(script.handle.fp=fopen(script.filename,"rb"))){ |
| 131 | fprintf(stderr,"Unable to open : %s\n",argv[1]); |
| 132 | return -1; |
| 133 | } |
| 134 | |
| 135 | argc--; |
| 136 | argv++; |
| 137 | |
| 138 | PHP_EMBED_START_BLOCK(argc,argv) |
| 139 | php_execute_script(&script TSRMLS_CC); |
| 140 | PHP_EMBED_END_BLOCK() |
| 141 | |
| 142 | return 0; |
| 143 | } |
| 144 | }}} |
| 145 | |
| 146 | == Compile the code snipest == |
| 147 | |
| 148 | Now that you get the file test_phpembed.c, you have to compile it before trying to run. You could use the following commands to achieve that compilation process : |
| 149 | |
| 150 | {{{ |
| 151 | #!sh |
| 152 | gcc -o test_phpembeded.o test_phpembeded.c -c $(/usr/lib/php5.2.10/bin/php-config --includes) |
| 153 | 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 |
| 154 | }}} |
| 155 | |
| 156 | You should succeed runing the command above, else open a ticket please to inform us that there is issue following those instructions :) |
| 157 | |
| 158 | == Run the code snipest == |
| 159 | |
| 160 | The last step to get your PHP embeded in yoru C program is to write a small php piece a .... code :) |
| 161 | |
| 162 | |
| 163 | {{{ |
| 164 | #!sh |
| 165 | cat > info.php <<EOF |
| 166 | <? phpinfo(); ?> |
| 167 | EOF |
| 168 | }}} |
| 169 | |
| 170 | Here we are, we now run the test_phpembed program to see if it was able to load and run the php script called info.php : |
| 171 | |
| 172 | {{{ |
| 173 | #!sh |
| 174 | LD_LIBRARY_PATH="/usr/lib/php5.2.10/lib/" ./test_phpembeded /var/www/localhost/htdocs/info.php | less |
| 175 | }}} |
| 176 | |
| 177 | Note that we have to set the LD_LIBRARY_PATH at runtime as we didn't install the php embed library in a stadard fashion (not in the standard search path - /usr/lib or /usr/local/lib- to ensure that we don't interfer with your allready installed php library). Neevertheless, when ZooKernel will be compiled you only have ot 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 do something like that also). |
| 178 | |