Simple PHP AMI Script dont work

Hello guys,

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

<?php
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");
$wrets=fgets($socket,128);
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" );
$wrets=fgets($socket,128);
?>

what can be the problem?

regards
philip

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?