Simple PHP AMI Script dont work

Hello guys,

I’ve got a problem with a simple script.
the script works fine on freepbx distro with asterisk
with freepbx distro with asterisk i get the following error in CLI ast_careful_fwrite: fwrite() returned error

header ("Content-type: text/html; charset=utf-8");
header ("Cache-Control: no-cache, must-revalidate");  // HTTP/1.1
header ("Pragma: no-cache");

$rufnummmer_original = $_REQUEST['rufnummer'];
$telefon = $_REQUEST['telefon'];
$callerid = $_REQUEST['callerid'];

$socket = fsockopen(localhost,"5038", $errno, $errstr, 4);
fputs($socket, "Action: Login\r\n");
fputs($socket, "UserName: user\r\n");
fputs($socket, "Secret: password\r\n\r\n");
fputs($socket, "Action: Originate\r\n" );
fputs($socket, "Channel: Local/[email protected]$context\r\n" );
fputs($socket, "Callerid: $callerid\r\n" );
fputs($socket, "Exten: $rufnummer\r\n" );
fputs($socket, "Context: from-internal\r\n" );
fputs($socket, "Priority: 1\r\n" );
fputs($socket, "Async: yes\r\n\r\n" );

what can be the problem?


UPDATE: the same script from a remote webserver works fine … then i use the IP of freepbx and not localhost.

sleep(1); in front of ORIGINATE and it works

Is there a reason why you aren’t just using the Asterisk Manager PHP Class? All of the functions are already written for you. Unless you are trying to learn?