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

As an exercise, I try to follow these instructions on Using Perl Code from PHP (devzone.zend.com).

The environment is as follows:

$ perl -v | grep built This is perl, v5.8.5 built for i386-linux-thread-multi $ php -v | grep built PHP 5.1.6 (cli) (built: Jun 17 2007 11:44:56)
I downloaded this package and compiled as follows:
export PHP_PREFIX="/usr" export PERL_PREFIX="/usr" $PHP_PREFIX/bin/phpize ./configure --with-perl=$PERL_PREFIX --with-php-config=$PHP_PREFIX/bin +/php-config make sudo make install
Then I did a added extension=perl.so to /etc/php.ini:
$ grep -i extension /etc/php.ini | grep -v '^;' extension_dir = "/usr/lib/php/modules" extension=perl.so
The shared perl library seems to be in place:
$ ll /usr/lib/php/modules/ | grep perl -rwxr-xr-x 1 root root 150234 May 6 08:56 perl.so
But when I try to run this simple sample, I get the error below:
$ cat perl.php <?php $perl = Perl::getInstance(); ?> $ php perl.php PHP Fatal error: Call to undefined method Perl::getinstance() in perl.php on line 2
Has anyone succeeded interfacing perl from php using the above approach?

(Note that I also tried PHP::Interpreter without success. make test reports PHP/Interpreter/Interpreter.so: undefined symbol: _zval_ptr_dtor).

Update (RESOLVED): I made a mistake when copying sample code, as kindly noted by moritz:

$ cat call.perl.from.php <?php #$perl = Perl::getInstance(); $perl = new Perl(); $perl->eval(" print \"Executing Perl code in PHP\n\" "); ?> $ php call.perl.from.php Executing Perl code in PHP
--
No matter how great and destructive your problems may seem now, remember, you've probably only seen the tip of them. [1]

Replies are listed 'Best First'.
Re: Using Perl Code from PHP
by moritz (Cardinal) on May 06, 2008 at 09:01 UTC
    The link you gave uses $perl = new Perl();, not $perl = Perl::getInstance();. I don't know any PHP, so I can't predict if that will make a difference.

    And for me this looks much like a PHP question, not a perl one.

      $perl = new Perl();
      That works nicely. Thank you moritz.
      And for me this looks much like a PHP question, not a perl one.
      Well, I agree that it's a PHP question. Meanwhile, I think creating interfaces to perl from other languages is a discussion worth taking here.
      --
      No matter how great and destructive your problems may seem now, remember, you've probably only seen the tip of them. [1]
        hi andreas i have the same proplem with "I also tried PHP::Interpreter without success. make test reports PHP/Interpreter/Interpreter.so: undefined symbol: _zval_ptr_dtor" So , did you found a solution for this proplem ?