AMI GetConfig missing lines

I have a strange problem with the Asterisk Manager Interface. I have tried to isolate the problem by writing a simple program that demonstrates it. Here is the program:


function output($socket){
	echo "Waiting for output\n";
		$line = fgets($socket);
		printf("line %d = %s",$i++,$line);
	} while($line!=false && strlen($line)>2);

$address = "remote address";
$port = 5038;

echo "opening socket to $address port $port\n";
$socket = fsockopen($address,$port, $errno, $errstr, 1) or die("Failed to open socket ".

echo "Socket open\n";
$login="Action: Login\r\nUserName: $username\r\nSecret: $secret\r\nEvents: off\r\n\r\n";
fputs($socket, $login);

$manconf = "Action: GetConfig\r\nFilename: manager.conf\r\n\r\n";

fputs($socket,"Action: Logoff\r\n\r\n");

fclose($socket) or die("Failed to close sockect\n");
echo "Socket closed\n";


The manager.conf in question (with xxxxxx replacing real values):

enabled = yes
port = 5038
bindaddr =
displayconnects = yes   ; Display on CLI user login/logoff
secret = xxxxxx
read = system,call,log,verbose,agent,user,config,dtmf,reporting,cdr,dialplan
write = system,call,agent,user,config,command,reporting,originate
writetimeout = 10000
secret = xxxxxx
read = system,call,log,verbose,agent,user,config,dtmf,reporting,cdr,dialplan
write = system,call,agent,user,config,reporting

And this is the output:

opening socket to xxxxxx 5038
Socket open
Waiting for output
line 0 = Asterisk Call Manager/1.1
line 1 = Response: Success
line 2 = Message: Authentication accepted
line 3 = 
Waiting for output
line 0 = Response: Success
line 1 = Category-000000: general
line 2 = Line-000000-000000: enabled=yes
line 3 = Line-000000-000001: port=5038
line 4 = Line-000000-000002: bindaddr=
line 5 = Line-000000-000003: displayconnects=yes
line 6 = Line-000001-000000: secret=xxxxxx
line 7 = Line-000001-000001: read=system,call,log,verbose,agent,user,config,dtmf,reporting,cdr,dialplan
line 8 = Line-000001-000002: write=system,call,agent,user,config,command,reporting,originate
line 9 = Category-000002: xxxxxx
line 10 = Line-000002-000000: secret=xxxxxx
line 11 = Line-000002-000001: read=system,call,log,verbose,agent,user,config,dtmf,reporting,cdr,dialplan
line 12 = Line-000002-000002: write=system,call,agent,user,config,reporting
line 13 = 
Waiting for output
line 0 = Socket closed

As you see, there is line missing - there is no Category-000001. Asterisk version is, but I have seen the same problem with 10.0.0-beta1. The problem is reproducible, in that every time I run the program I get the same output. However, if I use a different method, e.g. a telnet terminal session, I get the correct output.

Any ideas?