# HELP! broken pipe error in agi script

**URL:** <https://community.asterisk.org/t/help-broken-pipe-error-in-agi-script/30488>\
**Category:** Asterisk Support\
**Created:** [February 10, 2010, 3:26am UTC](https://community.asterisk.org/t/help-broken-pipe-error-in-agi-script/30488 "2010-02-10T03:26:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/asterisk/original/2X/4/475d0c889911cfb84ac4881ad6df8b523e3f9105.png) [@system](https://community.asterisk.org/u/system)\
**Post date:** [February 10, 2010, 3:26am UTC](https://community.asterisk.org/t/help-broken-pipe-error-in-agi-script/30488/1 "2010-02-10T03:26:44Z")

</div>

Hello good day,

I am new to agi scripting. I am doing a project on asterisk 1.6 and sugarcrm integration. I want to access the sugarCRM database through AGI, i tried using the script below but it seems there’s a problem in accessing the sugarCRM… please help, any ideas why this doesn’t work?

phpscript,php

#!/usr/bin/php -q

\<?php session\_start(); set\_time\_limit(30); require('phpagi.php'); error\_reporting(E\_ALL); $agi = new AGI(); $agi-\>answer(); $callernumber = $agi-\>request["agi\_callerid"]; $callername = $agi-\>request["agi\_calleridname"]; $agi-\>say\_digits($callernumber); $agi-\>verbose("\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*mysql start\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*",1); $openDB = mysql\_connect("http://localhost","root","")or die('Cannot connect to database!!!'); mysql\_select\_db("sugarcrm", $openDB); $agi-\>verbose("\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*mysql start22222\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*",1); ?\>

extensions.conf  
exten =\> 3000,1,AGI(phpscript.php)  
exten =\> 3000,2,Dial(SIP/3000,30)  
exten =\> 3000,n,Hangup

output in cli  
phpscript.php: AGI Request:  
phpscript.php: Array  
phpscript.php: (  
phpscript.php: [agi\_request] =\> phpscript.php  
phpscript.php: [agi\_channel] =\> SIP/3001-00000009  
phpscript.php: [agi\_language] =\> en  
phpscript.php: [agi\_type] =\> SIP  
phpscript.php: [agi\_uniqueid] =\> 1265770344.9  
phpscript.php: [agi\_version] =\> 1.6.0.20  
phpscript.php: [agi\_callerid] =\> 3001  
phpscript.php: [agi\_calleridname] =\> cha  
phpscript.php: [agi\_callingpres] =\> 0  
phpscript.php: [agi\_callingani2] =\> 0  
phpscript.php: [agi\_callington] =\> 0  
phpscript.php: [agi\_callingtns] =\> 0  
phpscript.php: [agi\_dnid] =\> 3000  
phpscript.php: [agi\_rdnis] =\> unknown  
phpscript.php: [agi\_context] =\> incoming  
phpscript.php: [agi\_extension] =\> 3000  
phpscript.php: [agi\_priority] =\> 1  
phpscript.php: [agi\_enhanced] =\> 0.0  
phpscript.php: [agi\_accountcode] =\>  
phpscript.php: [agi\_threadid] =\> -1226949776  
phpscript.php: )I\>  
phpscript.php:  
phpscript.php: PHPAGI internal configuration:  
phpscript.php: Array  
phpscript.php: (  
phpscript.php: [phpagi] =\> Array  
phpscript.php: (  
phpscript.php: [debug] =\> 1  
phpscript.php: [error\_handler] =\> 1  
phpscript.php: [admin] =\> [admin@myserver.host.com](mailto:admin@myserver.host.com)  
phpscript.php: [hostname] =\> localhost.localdomain  
phpscript.php: [tempdir] =\> /var/spool/asterisk/tmp  
phpscript.php: )  
phpscript.php: LI\>  
phpscript.php: [asmanager] =\> Array  
phpscript.php: (  
phpscript.php: [server] =\> localhost  
phpscript.php: [port] =\> 5038  
phpscript.php: [username] =\> [root@localhost.localdomain](mailto:root@localhost.localdomain)  
phpscript.php: [secret] =\> password  
phpscript.php: )  
phpscript.php:  
phpscript.php: [fastagi] =\> Array  
phpscript.php: (  
phpscript.php: [setuid] =\> 1  
phpscript.php: [basedir] =\> /var/lib/asterisk/agi-bin/  
phpscript.php: )  
phpscript.php:  
phpscript.php: [festival] =\> Array  
phpscript.php: (  
phpscript.php: [text2wave] =\> /usr/bin/text2wave  
phpscript.php: )  
phpscript.php:  
phpscript.php: [cepstral] =\> Array  
phpscript.php: (  
phpscript.php: [swift] =\> /usr/local/bin/swift  
phpscript.php: [voice] =\> Allison-8kHz  
phpscript.php: )  
phpscript.php:  
phpscript.php: )  
phpscript.php:  
[Feb 10 10:52:25] NOTICE[3870]: channel.c:2941 \_\_ast\_read: Dropping incompatible voice frame on SIP/3001-00000009 of format ulaw since our native format has changed to 0x2 (gsm)  
phpscript.php: **mysql start** \*\*\*\*\*\*\*\*\*\*\*  
[Feb 10 10:52:27] ERROR[3870]: utils.c:1019 ast\_carefulwrite: write() returned error: Broken pipe  
[Feb 10 10:52:27] ERROR[3870]: utils.c:1019 ast\_carefulwrite: write() returned error: Broken pipe

can anyone please help?  
i am using asterisk 1.6.0.20

thanks

---

<div class="post-metadata">

**Author:** ![david55](https://avatars.discourse-cdn.com/v4/letter/d/e19adc/32.png) [@david55](https://community.asterisk.org/u/david55)\
**Post date:** [February 10, 2010, 11:43am UTC](https://community.asterisk.org/t/help-broken-pipe-error-in-agi-script/30488/2 "2010-02-10T11:43:14Z")

</div>

You didn’t read standard input completely before exitting. When this happended to us, recently, it was due to leaving in debug code that wrote to standard output, and therefore provoked unexpected error responses from Asterisk.

---

<div class="post-metadata">

**Author:** ![navaismo](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/navaismo/32/2481_2.png) [@navaismo](https://community.asterisk.org/u/navaismo)\
**Post date:** [February 10, 2010, 4:12pm UTC](https://community.asterisk.org/t/help-broken-pipe-error-in-agi-script/30488/3 "2010-02-10T16:12:40Z")

</div>

Also try removing your verbose commands.
