Hello @snaggy,
It looks like a permission problem. Try to use this pattern in your file:
#!/usr/bin/env php
include '/etc/freepbx.conf';
include FreePBX::Config()->get('ASTAGIDIR')."/phpagi.php";
$agi = new AGI();
Thank you,
Daniel Friedman
Trixton LTD.