[solved] Manager API not reliable?

I’m having this strange issue and maybe someone can help:

I execute a php shell script from the dialplan via the System() command.

That script fires an originate statement over to manager and connects two extensions. One starts Meetme(), the other Ices().

I works like 5 times consecutively, then doesn’t 4 times, works again etc.

I have tried to isolate the problem and it turns out, that the System() command is allway fired, but the script therein is not. It goes like this (which should be rather straight forward):

<?php $socket = fsockopen("127.0.0.1", 5038, $errno, $errstr, 30); fwrite($socket,"Action: login\r\n"); fwrite($socket,"Username: bluepill\r\n"); fwrite($socket,"Secret: redpill\r\n\r\n"); fwrite($socket,"Action: Originate\r\n"); fwrite($socket,"Channel: Local/102@bureau\r\n"); fwrite($socket,"Context: bureau\r\n"); fwrite($socket,"Exten: 100\r\n"); fwrite($socket,"CallerID: 1234\r\n"); fwrite($socket,"Priority: 1\r\n"); fwrite($socket,"Timeout: 30000\r\n"); fwrite($socket,"ActionID: asdf1234\r\n\r\n"); $wrets=fgets($socket,128); ?>

When I add a clear error to it, errors are thrown into php.log absolutely everytime which proves that the script is executed ok.

What might cause the above script to work only sometimes? Are there other, more reliable ways to do what it does?

Thanks and cheers,
Konrad

I should add that invoking the script from command line with

works fine + absolutely everytime too. Only when called from the dialplan with System() does it fail.

Any hints or help would be greatly appreciated,
thanks and cheers,
Konrad

Totally going out on a limb here, but maybe try logging out of the Telnet session with the action.

Action: Logoff

Just a thought.

Very good point! This idea led me to examining the in- and output and finally to the solution:

<?php $socket = fsockopen("127.0.0.1", 5038, $errno, $errstr, 30); fwrite($socket,"Action: login\r\n"); fwrite($socket,"Username: redpill\r\n"); fwrite($socket,"Secret: bluepill\r\n\r\n"); fwrite($socket,"Action: Originate\r\n"); fwrite($socket,"Channel: Local/102@bureau\r\n"); fwrite($socket,"Context: bureau\r\n"); fwrite($socket,"Exten: 100\r\n"); sleep(1); fwrite($socket,"CallerID: 1234\r\n"); fwrite($socket,"Priority: 1\r\n"); fwrite($socket,"Timeout: 30000\r\n"); fwrite($socket,"ActionID: asdf1234\r\n\r\n"); $wrets=fgets($socket,128); ?>

The script is now executed absolutely everytime even from the dialplan.

Thanks, aluminumpork!