[Asterisk-Dev] PHP vs C

Kenneth Shaw ken at expitrans.com
Mon Nov 1 11:56:08 MST 2004


No. We gave up on AGI. It doesn't have much flexibility. We were even
working on a res_php, but determined it would be a lot easier to just
remotely control Asterisk via the Manager Interface.

We do something like this:

$leastcost_context = get_cheapest_route_context($phone);

$ast = AstManagerOpen();

$params = array(
	'Channel' => 'SIP/whatever@'.$_SERVER['REMOTE_ADDR'],
	'Context' => $leastcost_context,
	'Exten' => $phone,
	'Priority' => 1,
);

AstManagerExec($ast, 'Originate', $params);
AstManagerClose($ast);

Essentially, we wrote our own Manager functions, which we include & then
connect using the Originate command. The get_cheapest_route_context()
func is understood to return something like 'voipjet-out'.

Technically, you don't even have to use AGI or a remote PHP connect.
You could modify your extensions.conf to do something like this:

[lcr-routing]
exten => _1949.,Dial(Zap/1/${EXTEN:4})
exten => _1714.,Dial(sip/at_low_cost_provider/${EXTEN})

For every NPA out there. Of course, it gets more complicated based on if
you're doing LATA based connects, etc. Essentially, you end up with one
big-damn out-context if let's say in theory you had a different
provider/channel for each NPA. 

International is accomplished the same way, just different prefix/etc.

Asterisk needs a chan_lcr or something.


On Mon, 2004-11-01 at 12:27 -0600, Matthew Boehm wrote:
> Thanks for the info. We need our own LCR app because we will soon reach a
> point where we will have multiple carriers with different rates for inter vs
> intra, and intl vs intl-cell.
> Do you use the php apps as AGI? I mean, is the php script called from within
> * as an AGI?
> 
> Thanks,
> Matthew
> ----- Original Message ----- 
> From: "Kenneth Shaw" <ken at expitrans.com>
> To: "Asterisk Developers Mailing List" <asterisk-dev at lists.digium.com>
> Sent: Monday, November 01, 2004 11:40 AM
> Subject: Re: [Asterisk-Dev] PHP vs C
> 
> 
> > PHP.
> >
> > Use an Optimizer/Cacher like Turck MM Cache. This is essentially
> > compiling to byte code, and then running the PHP code.
> >
> > PHP Has tons of benefits, similar to the benefits of using Java, Python
> > or similar. The great benefit of PHP, we've found is its easy
> > integration with web services, which can't be beat. Surprisingly, PHP
> > won't slow down your system that much in terms of call connect time.
> > This of course is dependent on how many simul. connections you're
> > expecting.
> >
> > What you can always do is do some kind of load balancing, if it becomes
> > an issue. In terms of cost, the extra hardware is more cost effective
> > than your developer's time would be. Estimate the amount of hours it
> > would take you to implement something in PHP/Java/Python/Whatever vs.
> > Standard C, and you'll probably realize that the "inefficiency" is a
> > good enough tradeoff.
> >
> > Currently, we're using nothing but PHP internally for our call agents.
> > They interact with a web based custom CRM solution, and the optimized
> > call routing is determined by our CRM libs, not by Asterisk. At peak, we
> > get maybe 2-3 connections per second, which handled across two 2.8 ghz
> > machines (one is DB/Web, the other is an Asterisk server), we are never
> > bogged down.
> >
> > Developing a nice little LCR system for Asterisk would be nice, and we'd
> > use if it you cared to develop it, but there's no real necessity to
> > develop it.
> >
> >
> > On Mon, 2004-11-01 at 11:20 -0600, Matthew Boehm wrote:
> > > Hey guys,
> > >  I'm getting ready to write a custom least cost routing app for our
> company
> > > and wanted to get some pro/con feedback on programming this app  a) in
> PHP
> > > as an AGI  or  b) in C as a loadable .so module
> > >
> > >  Would be nice if I could compile PHP code into a module but you can't
> > > compile PHP code (at least, I've never seen it).
> > >
> > > This app will be used on every call made thru the server so it needs to
> be
> > > fast and low cpu intensive. It will be accessing mysql and running at
> least
> > > 2 queries each execution.
> > >
> > >  I have no preference on the language. I am confident that I can program
> it
> > > in either, but I would rather choose the better language for this
> paticular
> > > case (ie, speed).
> > >
> > > Thanks,
> > > Matthew
> > >
> > > _______________________________________________
> > > Asterisk-Dev mailing list
> > > Asterisk-Dev at lists.digium.com
> > > http://lists.digium.com/mailman/listinfo/asterisk-dev
> > > To UNSUBSCRIBE or update options visit:
> > >    http://lists.digium.com/mailman/listinfo/asterisk-dev
> > >
> > -- 
> > Kenneth Shaw <ken at expitrans.com>
> > ExpiTrans, Inc.
> >
> > _______________________________________________
> > Asterisk-Dev mailing list
> > Asterisk-Dev at lists.digium.com
> > http://lists.digium.com/mailman/listinfo/asterisk-dev
> > To UNSUBSCRIBE or update options visit:
> >    http://lists.digium.com/mailman/listinfo/asterisk-dev
> 
> _______________________________________________
> Asterisk-Dev mailing list
> Asterisk-Dev at lists.digium.com
> http://lists.digium.com/mailman/listinfo/asterisk-dev
> To UNSUBSCRIBE or update options visit:
>    http://lists.digium.com/mailman/listinfo/asterisk-dev
> 
-- 
Kenneth Shaw <ken at expitrans.com>
ExpiTrans, Inc.




More information about the asterisk-dev mailing list