Asterisk manager


I am trying to get the status of a call using asterisk manager - here’s a snip of my php code:

$socket = fsockopen("x.x.x.x","5038", $errno, $errstr, $timeout);
fputs($socket, "Action: Login\r\n");
fputs($socket, "UserName: bruce\r\n");
fputs($socket, "Secret: mysecret\r\n\r\n");

fputs($socket, "Action: ExtensionState\r\n");
fputs($socket, "Context: MAXUP\r\n");
fputs($socket, "Exten: SIP/XXXXX\r\n");
fputs($socket, "ActionID: 1\r\n\r\n");

$wrets = fgets($socket,128);
fwrite(STDOUT,"EXEC Noop $wrets\n");

When I write $wrets using fwrite, all I see on the screen is the word Asterisk. Is there something else I need to do here?