Hmm, got it working locally (on the same box as FreePBX) but no matter whether I’m on a call or not the extension still just shows as ‘idle’. I also had to amend the IP in Asterisk Manager Users because it didn’t like 127.0.0.1 I had to enter the LAN IP of the server.
Yet when I login and do core show hints when NOT on a call I get
22@ext-local : PJSIP/22&Local/9022@ State:Idle Presence:away Watchers 23
and when on a call I get
22@ext-local : PJSIP/22&Local/9022@ State:InUse Presence:away Watchers 23
So not sure what could be going wrong!
aha! I deleted a //next to print_r and I can see:
 => Array
[Response] => Error
[Message] => Permission denied
so clearly even though I’m logged in there must be something else I need to do to obtain permission to get in?!
aha x 2 I’d disabled write access for the user, thinking this wouldn’t need it, but after enabling write access, it seems to work!
Brilliant, working now. So now I just need to work out how I’m going to call the script - do I setup a cron job to execute it every 30 seconds or so?