0

I am using phpagi for Asterisk Vicidial. I have one of the classes that I need to trace by writing some of the variables values to external log file while executing the program.

I have tried following two methods, but both were stoping the application from executing.

first:

file_put_contents ( string $filename , mixed $data [, int $flags = 0 [, resource $context ]] ) : int

second:

print_r(variable, value)

any help on how to write variables value on a log file will be appreciated.

Eng7
  • 632
  • 1
  • 8
  • 25

2 Answers2

1

Use the already-visible and usable agi logging feature in Vicidial AGI scripts. You'll find the version specific to your version of Vicidial scripts in any one of the AGI scripts on your system.

The function will look something like this:

sub agi_output
    {
    if ($AGILOG >=2)
            {
            ### open the log file for writing ###
            open(Lout, ">>$AGILOGfile")
                            || die "Can't open $AGILOGfile: $!\n";
            print Lout "$now_date|$script|$agi_string\n";
            close(Lout);
            }
            ### send to STDERR writing ###
    if ( ($AGILOG == '1') || ($AGILOG == '3') )
            {print STDERR "$now_date|$script|$agi_string\n";}
    $agi_string='';
    }

The execution will look something like:

if ($AGILOG) {$agi_string = "Perl Environment Dump:";   &agi_output;}
TheSatinKnight
  • 696
  • 7
  • 16
0

You can't just print_r to stdout, becuase stdout go to AGI incoming and control asterisk.

Use stderr or write to log file. When you writing to log file, remember, that asterisk running under asterisk user. So just provide correct permissions.

arheops
  • 15,544
  • 1
  • 21
  • 27
  • Thanks, but how can I write to a log file? – Eng7 Dec 13 '19 at 08:57
  • This question not related to asterisk(except you have test that you give permission to asterisk running user). https://stackoverflow.com/questions/19898688/how-to-create-a-logfile-in-php – arheops Dec 13 '19 at 12:31