Running Perl in PHP ... HELP!

software development

#1

I have a Perl script that I need to call from within a PHP page. The script runs fine from the command line and is running as a cron job without any problems,. However, when I try to execute it through PHP nothing happens. In fact the only error I get from print_r(error_get_last()) is a number 1.

I’ve tried exec(), passthru() and shell_exec() and all three gave me the same result.

What am I doing wrong?


#2
  • Create standalone myscript.x (perl, python, cgi, w/e).

  • chmod myscript.x to be executable by user (0700)

  • Call myscript.x from PHP

<?php $cmd='./myscript.x'; passthru($cmd); ?>

Maximum Cash Discount on any plan with MAXCASH

How To Install PHP.INI / ionCube on DreamHost


#3

Tried it. Didn’t work.

The script resides in the user directory which is the parent directory of the website directory where the PHP page is. Does that make a difference?


#4

Not really, as long as you include the path. If once removed, start it with …/

I think a gotcha might be that a passthru would set the current working directory as the directory from which the PHP call is made rather than the location of the perl script you’re actually calling, so you’ll have to be path-aware in the perl script itself.

Maximum Cash Discount on any plan with MAXCASH

How To Install PHP.INI / ionCube on DreamHost