How to execute a script

Can someone give me some direction?

I have a ring group (602). I would like to execute a script when this group is called, without interrupting the call flow. Would this go in extensions_custom.conf?

I don’t understand when the contents of the custom.conf are executed. I think I need to add a custom extension, add it to the ring group, then add something like this to extensions_custom.conf

[from-internal-custom]
exten=>5678,1,TrySystem(/var/…myscript.php > /dev/null 2>&1 &)
exten=>5678,Hangup()

Am I close?

Here’s a technique I have used. In your ring group create a “dummy” extension that no one would be likely to dial, for example:

****5678#

It should be the first extension in the list, and note the # at the end, it’s important. Then in extensions_custom.conf, in the [from-internal-custom] context, you would do something very similar to what you suggested:

[from-internal-custom]
exten=>****5678,1,TrySystem(/var/…myscript.php > /dev/null 2>&1 &)
exten=>****5678,Congestion

Note that the last line must be something that doesn’t end the call, so don’t use Hangup. I use Congestion, but Busy would also work.

Doing it this way, you do not need to create a custom Extension or anything like that. One reason to use such a weird format for the extension number is so there is little chance of getting it confused with an actual extension, and little chance of anyone dialing it accidentally.

So what happens is that when the ring group is called, it tries the “dummy” extension, and that executes the code in extensions_custom.conf. But because that code returns “congested”, it then moves on to the next extension in the Ring Group. This also works in Follow-Mes, which makes it handy if you want to execute custom code when a single extension is called, for example to send some kind of notification.

I can’t take credit for this technique; I found it in an article that has since been relocated to here:
How to send various types of notifications on an incoming call in FreePBX
Took me a while to find it, but you might find it instructive to read the whole thing.