Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I invoke a PHP script from Perl?

Tags:

php

perl

How can I call a PHP script from a Perl script and get its output as a variable?

like image 870
vasion Avatar asked Mar 24 '10 14:03

vasion


1 Answers

Using the backtick operator:

my $phpOutput = `/usr/bin/php-cli your-script.php`;

Note that you may have to edit the path to point to your php executable.

If you want to have the output as a stream you can also open with a pipe (Perl <3):

open PHPOUT, "/usr/bin/php-cli your-script.php|";
while (<PHPOUT>) {
  # do something with the current line $_
}

See perldoc -f open.

like image 80
p4bl0 Avatar answered Oct 23 '22 06:10

p4bl0