Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I can't make PHP::Interpreter work. I got it installed, but running it yields:
$ perl -wle 'use PHP::Interpreter' Can't load '/usr/local/lib/perl/5.8.8/auto/PHP/Interpreter/Interpreter +.so' for module PHP::Interpreter: /usr/local/lib/perl/5.8.8/auto/PHP/ +Interpreter/Interpreter.so: undefined symbol: zend_ce_traversable at +/usr/lib/perl/5.8/DynaLoader.pm line 225. at -e line 1 Compilation failed in require at -e line 1. BEGIN failed--compilation aborted at -e line 1.
I have
$ php5 -v PHP 5.2.4-2ubuntu5 with Suhosin-Patch 0.9.6.2 (cli) (built: Feb 27 200 +8 20:43:54) $ uname -a Linux foo 2.6.24-16-generic #1 SMP Thu Apr 10 13:23:42 UTC 2008 i686 G +NU/Linux $ perl -v This is perl, v5.8.8 built for i486-linux-gnu-thread-multi
I even tried the Makefile.PL from Making PHP::Interpreter easier to install (which worked with the following patch):
26c26 < my @incdirs = map { s/^-I//g; chomp; $_ } split(/ /, $inc); --- > my @incdirs = map { s/^-I//g; chomp; $_ } grep { /^-I/ } split(/ / +, $inc);
perl Makefile.PL says:
$ perl Makefile.PL using php version 5.2.4-2ubuntu5 using prefix /usr using includes -I/usr/include -I/usr/include/php5 -I/usr/include/php5/ +main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include +/php5/ext -I/usr/include/php5/ext/date/lib -D_LARGEFILE_SOURCE -D_FIL +E_OFFSET_BITS=64 using lddlflags -shared -L/usr/local/lib -L/usr/lib -L/usr/lib using libs -L/usr/lib -lphp5 Checking header files... using incdir '/usr/include' using incdir '/usr/include/php5' using incdir '/usr/include/php5/main' using incdir '/usr/include/php5/TSRM' using incdir '/usr/include/php5/Zend' using incdir '/usr/include/php5/ext' using incdir '/usr/include/php5/ext/date/lib' Found /usr/include/php5/Zend/zend.h Found /usr/include/php5/Zend/zend_ini.h Found /usr/include/php5/Zend/zend_interfaces.h Found /usr/include/php5/Zend/zend_compile.h Found /usr/include/php5/Zend/zend_API.h Found /usr/include/php5/TSRM/TSRM.h Found /usr/include/php5/main/php.h Found /usr/include/php5/main/php_config.h Found /usr/include/php5/main/php_ini.h Found /usr/include/php5/main/SAPI.h Found /usr/include/php5/main/php_main.h Note (probably harmless): No library found for -lphp5 Writing Makefile for PHP::Interpreter
make says:
$ make cp lib/PHP/Interpreter/Resource.pm blib/lib/PHP/Interpreter/Resource.p +m cp lib/PHP/Interpreter/Class.pm blib/lib/PHP/Interpreter/Class.pm cp a.pl blib/lib/PHP/a.pl cp b.pl blib/lib/PHP/b.pl cp lib/PHP/Interpreter.pm blib/lib/PHP/Interpreter.pm /usr/bin/perl /usr/share/perl/5.8/ExtUtils/xsubpp -typemap /usr/share +/perl/5.8/ExtUtils/typemap -typemap typemap PHP.xs > PHP.xsc && mv P +HP.xsc PHP.c cc -c -I/usr/include -I/usr/include/php5 -I/usr/include/php5/main -I/ +usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ex +t -I/usr/include/php5/ext/date/lib -D_LARGEFILE_SOURCE -D_FILE_OFFSET +_BITS=64 -g -O2 -DVERSION=\"1.0.1\" -DXS_VERSION=\"1.0.1\" -fPIC "- +I/usr/lib/perl/5.8/CORE" PHP.c In file included from /usr/include/php5/main/php.h:34, from phpinterp.h:11, from PHP.xs:13: /usr/include/php5/Zend/zend.h:34:1: warning: "END_EXTERN_C" redefined In file included from PHP.xs:3: /usr/lib/perl/5.8/CORE/perl.h:242:1: warning: this is the location of +the previous definition PHP.c: In function ‘XS_PHP__Interpreter__Resource_FETCH’: PHP.c:1438: warning: useless type name in empty declaration cc -c -I/usr/include -I/usr/include/php5 -I/usr/include/php5/main -I/ +usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ex +t -I/usr/include/php5/ext/date/lib -D_LARGEFILE_SOURCE -D_FILE_OFFSET +_BITS=64 -g -O2 -DVERSION=\"1.0.1\" -DXS_VERSION=\"1.0.1\" -fPIC "- +I/usr/lib/perl/5.8/CORE" phpinterp.c In file included from /usr/include/php5/main/php.h:34, from phpinterp.h:11, from phpinterp.c:13: /usr/include/php5/Zend/zend.h:34:1: warning: "END_EXTERN_C" redefined In file included from phpinterp.c:3: /usr/lib/perl/5.8/CORE/perl.h:242:1: warning: this is the location of +the previous definition cc -c -I/usr/include -I/usr/include/php5 -I/usr/include/php5/main -I/ +usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ex +t -I/usr/include/php5/ext/date/lib -D_LARGEFILE_SOURCE -D_FILE_OFFSET +_BITS=64 -g -O2 -DVERSION=\"1.0.1\" -DXS_VERSION=\"1.0.1\" -fPIC "- +I/usr/lib/perl/5.8/CORE" phpfuncs.c In file included from /usr/include/php5/main/php.h:34, from phpinterp.h:11, from phpfuncs.c:5: /usr/include/php5/Zend/zend.h:34:1: warning: "END_EXTERN_C" redefined In file included from phpfuncs.c:2: /usr/lib/perl/5.8/CORE/perl.h:242:1: warning: this is the location of +the previous definition phpfuncs.c: In function ‘zm_startup_sandwich’: phpfuncs.c:1054: warning: assignment from incompatible pointer type Running Mkbootstrap for PHP::Interpreter () chmod 644 Interpreter.bs rm -f blib/arch/auto/PHP/Interpreter/Interpreter.so cc -shared -L/usr/local/lib -L/usr/lib -L/usr/lib PHP.o phpinterp.o +phpfuncs.o -o blib/arch/auto/PHP/Interpreter/Interpreter.so \ \ chmod 755 blib/arch/auto/PHP/Interpreter/Interpreter.so cp Interpreter.bs blib/arch/auto/PHP/Interpreter/Interpreter.bs chmod 644 blib/arch/auto/PHP/Interpreter/Interpreter.bs Manifying blib/man3/PHP::Interpreter::Resource.3pm Manifying blib/man3/PHP::Interpreter::Class.3pm Manifying blib/man3/PHP::Interpreter.3pm $
make install says:
$ sudo make install Installing /usr/local/lib/perl/5.8.8/auto/PHP/Interpreter/Interpreter. +so Files found in blib/arch: installing files in blib/lib into architectu +re dependent library tree Writing /usr/local/lib/perl/5.8.8/auto/PHP/Interpreter/.packlist Appending installation info to /usr/lib/perl/5.8/perllocal.pod
Anyone who can guide a confused Monk in the quest for enlightenment?

Replies are listed 'Best First'.
Re: use PHP::Interpreter throws undefined symbol: zend_ce_traversable
by Herkum (Parson) on Jun 02, 2008 at 21:19 UTC

    I would hazard a guess that your php libraries are out-of-date or it compiles an .so which is out-dated. That is usually what happens when you see this sort of errors with other perl modules.

      I would hazard a guess that your php libraries are out-of-date or it compiles an .so which is out-dated.
      Well, first I tried the stock php from ubuntu (php 5.2.4-2ubuntu5), which gave the above error.

      Then I reverted to the php released prior to the last release of PHP::Interpreter, which was: php-5.0.5 (05 Sep 2005). It failed with the same error: undefined symbol: zend_ce_traversable.

      Then I tried the most recent php from source: php-5.2.6 (01 May 2008). Which also fail in the same way.

      What can I do to resolve the out-date issue?

        I could not find anything on Google and zend_ce_traversable definitely looks to be a part of a PHP header file. So the question is where is the error?

        Lets assume that it is not PHP, then it might be the make for the module. That is something that is out of my scope of knowledge. I looked up PHP::Interpeter and the last release is Sep 2005 and noticed that 7 out of 8 system tests fail. I would say that the module itself got broke at some point when PHP was getting updated.

        I am afraid you might be out of look with this module. However, I did a PHP module that might do what you are looking for. It is a little more current in support and passed smoke tests on 5.8.8 on Linux 2.6.22.10.

        Good luck

Re: use PHP::Interpreter throws undefined symbol: zend_ce_traversable
by andreas1234567 (Vicar) on Nov 11, 2008 at 20:39 UTC
    Note (probably harmless): No library found for -lphp5
    This is not harmless, in fact, PHP::Interpreter won't work unless the php library (i.e. /usr/local/lib/libphp5.so on Linux) is found. I think part of the problem is that the stock php is not configure'd with the --enable-embed option:
    ./configure --enable-embed
    Download the php sources, compile and install. php will by default install itself into /usr/local on a Linux system, and the stock Makefile.PL assumes both the php header files and the php libraries can be found there.

    The README contains build instructions (which BTW works with php 5.2.x also):

    1) Download the PHP sources from php.net 2) tar zxf php-5.1.x.tar.gz 3) cd php-5.1.x 4) ./configure --enable-embed [any other options you want] 5) make 6) make install 7) install PHP::Interpreter
    Checkpoints:
    • After step 6 but before step 7, check that libphp5.so can be found in /usr/local/lib.
    • In step 7, during perl Makefile.PL, make sure you don't get the No library found for -lphp5.
    --
    No matter how great and destructive your problems may seem now, remember, you've probably only seen the tip of them. [1]
      yum provides /usr/lib/libphp5.so and voilá : we need php-embedded-5.2.6-5.i386
        Yes, the lucky guys who have yum available just type

        yum install php-embedded

        Although you get the /usr/lib/libphp5.so immediately with this way, I ran into the problem there was another symbol missing for "dbase".

        So I compiled the latest version of PHP as suggested above on my notebook with additionally

        ./configure --enable-embed --enable-dbase

        Then, all you need to copy to another machine is the fresh created libphp5.so into /usr/lib. This binary was fully portable. compiled on Fedora 9, ran perfect on Fedora 5 as well.

        This shit runs amazingly fast. I'm using this wrapper for creating nice-looking PDFs with PHP's fpdf. Didn't see an easy-to-use PDF interface for Perl so far.

        So to conclude this second recipe and maybe increase the Google ranking for people who're seeking such answers here's the complete procedure that worked on 3 servers:

        1.) yum install php-devel

        2.) Download and compile the latest release of PHP from php.net
        	./configure --enable-embed --enable-dbase
        	make
        	make test
        	su -
        	make install
        
        You may compile this bundle on your Notebook for example (Guess we're talking about Linux on all systems ;). All you'll need later is the file "libphp5.so". So for future distributing the functionality of PHP::Interpreter you could omit this point.

        3.) Then, cd /usr/lib --> copy "libphp5.so" here.

        4.) force install PHP::Interpreter

        Have fun!
        --reto