2

I am currently working from home (on a Sunday!) and I am trying to figure out why my Perl script is returning NULL to PHP from where it is called. However, I don't see how I can debug the Perl script itself. The PHP file returns a warning that I am trying to do an array operation on a non-array object (because the expected array is actually NULL returned by PHP). The logs of the webserver have only logged this warning as well - no Perl errors.

Is there a place where specific 'external' logs are stored on a server? Or, is there a better way to debug a Perl file that is been run from a PHP file that is required in a main PHP file? Debugging isn't necessary (I don't need a debug mode) but I'd like to see the errors or warnings at least.

5
  • Can you change the source of the Perl script to add some debugging code? Commented Apr 24, 2016 at 16:20
  • @bart I can do that, indeed. What would I write? Commented Apr 24, 2016 at 16:38
  • Can you run the Perl program yourself without the php inbetween? Do you know what goes in and what is supposed to come out? Do you have shell access? Commented Apr 24, 2016 at 17:06
  • @simbabque No, I can only run the file from the PHP file, via the server. I do not have shell access. (Otherwise I would simply run the script from shell.) Commented Apr 24, 2016 at 17:08
  • So the debugger is not an option. The answer by bart is a good start, but it's also important to know what the program is supposed to do. I take it you can't install any modules either since you don't have shell access. Combine @bart's solution with a bunch of warn statements, possibly using Data::Dumper, and you should be able to find the problem. Commented Apr 24, 2016 at 17:17

1 Answer 1

3

You can add following code at the top of your Perl script:

sub debug_log
{
    open my $log_fh, ">>", "/tmp/debug.log";
    print $log_fh $_[0];
    warn $_[0];
    close $log_fh;
}

$SIG{__WARN__} = \&debug_log;
$SIG{__DIE__} = \&debug_log;

This way all the warnings and die messages should end up in /tmp/debug.log.

Sign up to request clarification or add additional context in comments.

2 Comments

Would that tmp directory be relative to the Perl file itself (so a sister of that script), to the PHP file, or to the main PHP file? Because on first glance I cannot find it.
The path specified as the open argument is absolute, so you should have a file in /tmp. If there is no file, then it means there were no warnings or the script did not die. You can test if the warnings are logged correctly, by using warn "debug test"; right after the $SIG... lines.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.