phpasteriskagi

How can I write to files through an agi php?


I am creating an agi in php for asterisk, very simple, what I want to do is to save a text in a file, however, when I execute the plan dial, the agi does not save the file

my asterisk version is 13.8.3, this run over ubuntu 18, my php version is 7.2

#!/usr/bin/php -q
<php
    $agivars = array();
    while(!feof(STDIN)) {
        $agivar = trim(fgets(STDIN));
        if($agivar === '') {
            break;
        }
        $agivar = explode(':', $agivar);
        $agivars[$agivar[0]] = $agivar[1];
    }
    echo "Verbose beforeSave\n";
    file_put_contents("/a.txt", "helloWorld");
    echo "Verbose afterSave\n";
?>

i expect a file named a.txt in / dir


Solution

  • Please note, on most system asterisk running under asterisk user and it can't write to root-owned files.

    So check your permissions.

    Also no need write your own AGI code, use phpagi project.