Help, Can't get Originate to work in PHP

Comment on Asterisk manager Example: PHP
Joined: Mon 21 of Nov, 2005

Re: Help, Can't get Originate to work in PHP

Posted:Thu 14 of Feb, 2008 (04:28 UTC)

// this is a a sample on how to deal with Manager API with PHP

$socket = fsockopen("","5038", $errno, $errstr, $timeout);
fputs($socket, "Action: Login\r\n");
fputs($socket, "UserName: admin\r\n");
fputs($socket, "Secret: blabla\r\n\r\n");

fputs($socket, "Action: Command\r\n");
fputs($socket, "Command: reload\r\n\r\n");
$wrets=fgets($socket,128); // this line is the most important of all don't forget it :-)
Joined: Mon 13 of Aug, 2007

Help, Can't get Originate to work in PHP

Posted:Mon 13 of Aug, 2007 (20:17 UTC)
This one has me stumped. If I telnet into the Asterisk Manager and perform these actions, it will dial my extention and then dial the outside number as expected, works great.

Action: login
Username: admin
Secret: amp111

Action: originate
Channel: SIP/614
Context: from-internal
Exten: 1234567
Priority: 1
Callerid: Web Call to 123-4567

But when I put them in a PHP script, the script just logs in then out. Below is the script, then the results as seen in the *CLI.

$oSocket = fsockopen($strHost, 5038, $errnum, $errdesc) or die("Connection to host failed");
fputs($oSocket, "Action: login\r\n");
fputs($oSocket, "Events: off\r\n");
fputs($oSocket, "Username: admin\r\n");
fputs($oSocket, "Secret: amp111\r\n\r\n");
fputs($oSocket, "Action: originate\r\n");
fputs($oSocket, "Channel: SIP/614\r\n");
fputs($oSocket, "Context: from-internal\r\n");
fputs($oSocket, "CallerId: Web Call to 123-4567\r\n");
fputs($oSocket, "Exten: 1234567\r\n");
fputs($oSocket, "Priority: 1\r\n\r\n");
fputs($oSocket, "Action: Logoff\r\n\r\n");

  • CLI
== Manager 'admin' logged on from
== Manager 'admin' logged off from

I have researched everything I can find on the web and I can't figure out why this doesn't work.
Any ideas???? This is driving me nuts.

Thanks in advance.