!sorry for repost. I used Chrome with Hotmail again which garbles the text.
Hi Everyone,
Trying to pass ${EXTEN} to a php file for processing. Not sure how to. The php file takes $did_numb as defined:
<?php
$did_numb = $_GET['did_numb'];
?>
I know that http://serverIP/file.php?did_numb=416-444-5555 works fine but when calling php file by system() from dialplan how can this be done?
exten => s,n,system(php file.php?did_numb=${EXTEN}) |||| This method doesn't work as "php file.php?did_numb=416-444-555" simply doesn't work from the CentOS prompt.
What is the proper syntax here?
I also want whatever that file.php returns to be saved in $var for later usage in dial-plan afterwards.
Thanks.
Your Photo on Bing.ca: You Could WIN on Canada Day! Submit a Photo Now!
Turn down-time into play-time with Messenger games Play Now!
_________________________________________________________________
Learn more ways to connect with your buddies now
http://go.microsoft.com/?linkid=9734388
----- Original Message -----
> Trying to pass ${EXTEN} to a php file for processing. Not sure how to.
> The php file takes $did_numb as defined:
>
>
> <?php
>
> $did_numb = $_GET['did_numb'];
> ?>
There are two ways to do this. If you insist on using a system() call you could pass the variable as an aguement. I don't recall how to use the system() function to pass an argument so I'll guess here:
exten => s,n,system(php file.php "${EXTEN}")
Then in PHP use:
#!/usr/bin/php
<?php
$did_numb = $_GLOBALS['argv'][1]
?>
>
> I know that http://serverIP/file.php?did_numb=416-444-5555 works fine
> but when calling php file by system() from dialplan how can this be
> done?
>
>
> exten => s,n,system(php file.php?did_numb=${EXTEN}) |||| This method
> doesn't work as "php file.php?did_numb=416-444-555" simply doesn't
> work from the CentOS prompt.
>
>
> What is the proper syntax here?
>
>
> I also want whatever that file.php returns to be saved in $var for
> later usage in dial-plan afterwards.
Okay so what you really want is to use AGI. Get an AGI library for PHP. I recall using one called phpagi.php (http://sourceforge.net/projects/phpagi/)
You will want to use the get_variable() and set_variable() functions.
Again from memory:
exten => s,n,agi(file.php)
Then the PHP code
#!/usr/bin/php
<?php
// Use the phpagi library
require "phpagi.php';
// It's an object so let's instantiate it
$agi = new AGI();
// Get a variable from dial plan
$agi->get_variable($EXTEN);
// do something, like assign a value to $var
$var = "something";
// Set a dial plan variable
$agi->set_variable("var", $var);
exit(0);
?>
--
John Van Ostrand
CTO, co-CEO
Net Direct Inc.
564 Weber St. N. Unit 12, Waterloo, ON N2L 5C6
Ph: 866-883-1172 x5102
Fx: 519-883-8533
Linux Solutions / IBM Hardware
---------------------------------------------------------------------
To unsubscribe, e-mail: asterisk-u...@uc.org
For additional commands, e-mail: asteri...@uc.org
However when doing a NoOp I am getting channel info like ip and sip info for the variable. It seems to me that the variable is not passed the right way back to the dial-plan.
NoOp reults:
NoOp("SIP/64.64.65.65-00000d31", "") in new stack
Maybe the problem:
$agi->set_variable("var", $var);
-Bruce
> Date: Sun, 13 Jun 2010 16:16:48 -0400
> From: jo...@netdirect.ca
> To: het...@hotmail.com
> CC: aste...@uc.org
> Subject: Re: [on-asterisk] How to pass ${EXTEN} from dialplan to php file which accept variable $did_numb ???
_________________________________________________________________
Game on: Challenge friends to great games on Messenger
http://go.microsoft.com/?linkid=9734387
Just so I'm clear, your doing something like:
exten => s,n,NoOP(${var})
And getting the results you mention? that doesn't show a channel name, but rather that ${var} contains "".
You probably want quite on the php, that could screw up the set_variable stuff.
#!/usr/bin/php -q
Of use the -q argument when invoking php.
P.S. There is a typo in my code below. The get_variable command should be:
$agi->get_variable("EXTEN");
> Maybe the problem:
>
> $agi->set_variable("var", $var);
> >
Thanks,
Bruce
> Date: Mon, 14 Jun 2010 16:13:33 -0400
> From: jo...@netdirect.ca
> To: het...@hotmail.com
> CC: aste...@uc.org
> Subject: Re: [on-asterisk] How to pass ${EXTEN} from dialplan to php file which accept variable $did_numb ???
>
_________________________________________________________________
Look 'em in the eye: FREE Messenger video chat
http://go.microsoft.com/?linkid=9734386
I think you need to use the Manager API for that. Two ways:
You could use PHP's system() call to run "asterisk -r ...." and capture and parse the output.
Or you could get a asterisk manager library for PHP and do it as a function.
Which you choose depends on how often Asterisk will call the AGI script.
$sip_peer = 2342342342
$peer_count = system('asterisk -rx "sip show peer $sip_peer" | grep -c "X-Lite"', $retval);
Above is supposed to return 1 if $sip_peer is registered (by utilizing grep -count) with X-Lite as word found and 0 if it is not registered but it always returns 0, I think because the " " are confusing php.
I searched and since no one probably uses asterisk -rx this way, there are no results on google. In addition, php people never use asterisk -rx either....so their solutions never include the use of " " inside ' '
What could be the escape charecter for I guess "sip show peer $sip_peer" and "X-Lite" part so it returns the proper value back.
Thanks,
Bruce
> Date: Mon, 14 Jun 2010 18:22:06 -0400
> From: jo...@netdirect.ca
> To: het...@hotmail.com
> CC: aste...@uc.org
> Subject: Re: [on-asterisk] How to pass ${EXTEN} from dialplan to php file which accept variable $did_numb ???
>
$peer_count = system("sudo /usr/sbin/asterisk -rx " . escapeshellarg("sip show peer $sip_peer\"\"") . " | grep -c X-Lite");
Thanks for all the help everyone.
Bruce
Date: Mon, 14 Jun 2010 22:06:55 -0400
Subject: Re: [on-asterisk] How to pass ${EXTEN} from dialplan to php file which accept variable $did_numb ???
From: rafael....@gmail.com
To: het...@hotmail.com
Bruce,
Try this instead:
$peer_count = system("asterisk -rx \"sip show peer $sip_peer\" | grep -c \"X-Lite\"", $retval);
In php, when you use single quotes, the string will be interpreted as is, statically. Only when you use double quotes you'll have the variables getting translated.
Rafael
--
Rafael Carneiro
http://ca.linkedin.com/in/rcarneiro