I&#39;ve observed the same behavior. This is what happens when you close the socket before logoff is completed. You need to wait until the logoff action is completed before closing the socket (your fclose() call). Alternately, use a proxy or a daemon that will sit between your script and the AMI and keep the socket open.<div class="gmail_extra">
<br><br><div class="gmail_quote">On Wed, Dec 12, 2012 at 12:44 PM, Faheem <span dir="ltr">&lt;<a href="mailto:faheem_imt@yahoo.com" target="_blank">faheem_imt@yahoo.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div style="font-size:12pt;font-family:arial,helvetica,sans-serif"><div style="font-family:arial,helvetica,sans-serif;font-size:12pt"><span>Hi,</span></div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:arial,helvetica,sans-serif">
<span>I&#39;m getting errors while originating a call through AMI.</span></div><div style="background-color:transparent"><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:arial,helvetica,sans-serif">
[Dec 12 21:18:35] ERROR[8661]: utils.c:1236 ast_careful_fwrite: fwrite() returned error: Broken pipe</div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:arial,helvetica,sans-serif">[Dec 12 21:18:35] ERROR[8661]: utils.c:1236 ast_careful_fwrite: fwrite() returned error: Broken
 pipe</div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:arial,helvetica,sans-serif">[Dec 12 21:18:35] ERROR[8661]: utils.c:1236 ast_careful_fwrite: fwrite() returned error: Broken pipe</div>
<div style="font-style:normal;font-size:16px;font-family:arial,helvetica,sans-serif">Asterisk version 11.0.1</div><div style="font-style:normal;font-size:16px;font-family:arial,helvetica,sans-serif">OS: <span style="background-color:transparent">CentOS release 5.8 (Final)</span></div>
<div style="font-style:normal;font-size:16px;font-family:arial,helvetica,sans-serif"><br></div><div style="font-style:normal;font-size:16px;font-family:arial,helvetica,sans-serif"><span style="background-color:transparent">//manager.conf settings</span><br>
</div><div><div><span style="font-size:13px">[faheem]</span></div><div><span style="font-size:small">secret =f@xxxxxx</span></div><div><span style="font-size:small">permit=<a href="http://127.0.0.1/255.255.255.255" target="_blank">127.0.0.1/255.255.255.255</a></span></div>
<div><span style="font-size:small">read = system,call,log,verbose,agent,user,config,dtmf,reporting,cdr,dialplan</span></div><div><span style="font-size:small">write = system,call,agent,user,config,command,reporting,originate</span></div>
<div style="font-style:normal;font-size:16px;font-family:arial,helvetica,sans-serif"><br></div></div><div style="font-style:normal;font-size:16px;font-family:arial,helvetica,sans-serif"><span style="background-color:transparent;font-size:13px">///AMI script</span><br>
</div></div><div style="background-color:transparent"><div style="background-color:transparent"><span style="font-size:small">&lt;?php</span></div><div style="background-color:transparent"><span style="font-size:small"><br>
</span></div><div style="background-color:transparent"><span style="font-size:small">$sys_ip = &quot;127.0.0.1&quot;;</span></div><div style="background-color:transparent"><span style="font-size:small">$User_str = &quot;faheem&quot;;</span></div>
<div style="background-color:transparent"><span style="font-size:13px">$Secret_str = &quot;f@h33m112xxxxxx&quot;;</span></div><div style="background-color:transparent"><span style="font-size:small">$phoneNumb = 1234;</span></div>
<div style="background-color:transparent"><span style="font-size:small">$dialNumb =  4567;</span></div><div style="background-color:transparent"><span style="font-size:small">$spoofNumb = 786;</span></div><div style="background-color:transparent">
<span style="font-size:13px">$context = &quot;xxxxx-xxxxx&quot;;</span></div><div style="background-color:transparent"><span style="font-size:small"><br></span></div><div style="background-color:transparent"><span style="font-size:small">$oSocket = fsockopen($sys_ip, 5038, $errnum, $errdesc) or die(&quot;Connection to host failed&quot;);</span></div>
<div style="background-color:transparent"><span style="font-size:13px;background-color:transparent">fputs($oSocket, &quot;Action: login\r\n&quot;);</span><br></div><div style="background-color:transparent"><span style="font-size:13px">fputs($oSocket, &quot;Username: $User_str\r\n&quot;);</span></div>
<div style="background-color:transparent"><span style="font-size:small">fputs($oSocket, &quot;Secret: $Secret_str\r\n\r\n&quot;);</span></div><div style="background-color:transparent"><span style="font-size:small">fputs($oSocket, &quot;Events: off\r\n\r\n&quot;);</span></div>
<div style="background-color:transparent"><span style="font-size:small">fputs($oSocket, &quot;Action: originate\r\n&quot;);</span></div><div style="background-color:transparent"><span style="font-size:small">fputs($oSocket, &quot;Channel: SIP/testTrunk/$phoneNumb\r\n&quot;);</span></div>
<div style="background-color:transparent"><span style="font-size:small">fputs($oSocket, &quot;Exten: $dialNumb\r\n&quot;);</span></div><div style="background-color:transparent"><span style="font-size:small">fputs($oSocket, &quot;Context: $context\r\n&quot;);</span></div>
<div style="background-color:transparent"><span style="font-size:small">fputs($oSocket, &quot;Priority: 1\r\n\r\n&quot;);</span></div><div style="background-color:transparent"><span style="font-size:small">fputs($oSocket, &quot;Timeout: 10000\r\n&quot;);</span></div>
<div style="background-color:transparent"><span style="font-size:13px">fputs($oSocket, &quot;CallerId: $spoofNumb\r\n&quot;);</span></div><div style="background-color:transparent"><span style="font-size:small">fputs($oSocket, &quot;Async: false\r\n&quot;);</span></div>
<div style="background-color:transparent"><span style="font-size:small">fputs($oSocket, &quot;Action: Logoff\r\n\r\n&quot;);</span></div><div style="background-color:transparent"><span style="font-size:small">echo &quot;originate executed&quot;;</span></div>
<div style="background-color:transparent"><span style="font-size:small">fclose($oSocket);</span></div><div style="background-color:transparent"><span style="font-size:small"><br></span></div><div style="background-color:transparent">
<span style="font-size:small">?&gt;</span></div><div style="font-style:normal;font-size:16px;font-family:arial,helvetica,sans-serif"><br></div></div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:arial,helvetica,sans-serif">
<br></div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:arial,helvetica,sans-serif"><div>Can any one please help me over it.</div><div>Thank you!</div><div><span style="font-size:12pt"> </span><br>
</div></div><div style="font-family:arial,helvetica,sans-serif;font-size:12pt"><div>Muhammad Faheem</div>  <div><br><br></div></div></div></div><br>--<br>
_____________________________________________________________________<br>
-- Bandwidth and Colocation Provided by <a href="http://www.api-digital.com" target="_blank">http://www.api-digital.com</a> --<br>
New to Asterisk? Join us for a live introductory webinar every Thurs:<br>
               <a href="http://www.asterisk.org/hello" target="_blank">http://www.asterisk.org/hello</a><br>
<br>
asterisk-users mailing list<br>
To UNSUBSCRIBE or update options visit:<br>
   <a href="http://lists.digium.com/mailman/listinfo/asterisk-users" target="_blank">http://lists.digium.com/mailman/listinfo/asterisk-users</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br>-Chris Harrington<br>
<div>ACSDi Office: 763.559.5800</div><div><div>Mobile Phone: 612.326.4248</div></div><div><br></div><br>
</div>