I would recommend that you adjust your DB check code to run in a loop. CDR submission occurs <i>after</i> CHANNEL_HANGUP - so you have a race condition and may check the DB before the CDR has been committed. You'd need to handle a) trying again after a short delay if the CDR isn't there yet and b) a timeout in case xml_cdr fails and the CDR isn't available (or the script'll keep running until it is).<br>
<div class="gmail_extra"><br><br><div class="gmail_quote">On 29 November 2012 19:23, Richard Gration <span dir="ltr"><<a href="mailto:richgration@gmail.com" target="_blank">richgration@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Steve,<br>
<br>
Thanks for all your help, I have working code now :-)<br>
<br>
I don't know if this is a local configuration "feature" but the events<br>
are returned synchronously from the "event plain CHANNEL_HANGUP" call,<br>
so I just loop looking for my uuid.<br>
<br>
Cheers,<br>
Rich<br>
<br>
PS For anyone interested in some alpha code ...<br>
<br>
$dExt = $_GET['dExt'];<br>
$pin = $_GET['pin'];<br>
<br>
if ($dExt and $pin) {<br>
<div class="im"> $fp = event_socket_create($host, $port, $password);<br>
<br>
</div> # How shall we abuse the callee today?<br>
$wav1 = 'ivr/32000/ivr-douche_telecom.wav';<br>
$wav2 = 'ivr/32000/ivr-thank_you_for_calling.wav';<br>
<div class="im"><br>
# Place call and find uuid<br>
</div> $cmd = "api originate<br>
{ignore_early_media=true,originate_timeout=30}sofia/external/677${dExt}@MGC<br>
'&play_and_get_digits(4 9 1 10000 # $wav1 $wav2 foo \d+)'";<br>
$response = event_socket_request($fp, $cmd);<br>
$response = strip_cr($response);<br>
<div class="im"> $bits = preg_split('/\s+/',$response);<br>
</div> $uuid = $bits[1];<br>
<br>
$continue = 1;<br>
$cmd = "event plain CHANNEL_HANGUP";<br>
while ($continue) {<br>
error_log("running $cmd");<br>
$response = event_socket_request($fp, $cmd);<br>
error_log("got $response");<br>
if (preg_match("/$uuid/",$response)) {<br>
$continue = 0;<br>
}<br>
}<br>
<br>
$dbhRo = DbConnect::GetConnection('db-readonly');<br>
$res_struct = mysql_query("SELECT strSrcMedia FROM cdr WHERE<br>
strSipSessionId = '$uuid'",$dbhRo);<br>
$res = mysql_fetch_array($res_struct);<br>
$pin_from_user = $res[0];<br>
$result = $pin == $pin_from_user ? 1 : 0 ;<br>
<br>
echo "<pre>";<br>
<div class="im"> echo date('H:i:s') . "\n";<br>
</div> echo "uuid = $uuid\n";<br>
echo "$result\n";<br>
echo "</pre>";<br>
<br>
# Close socket<br>
fclose($fp);<br>
} else {<br>
echo -1;<br>
<div class="HOEnZb"><div class="h5">}<br>
<br>
<br>
On 29 November 2012 13:56, Steven Ayre <<a href="mailto:steveayre@gmail.com">steveayre@gmail.com</a>> wrote:<br>
>> ... how I listen for these events. Is it just a case of polling the<br>
>> socket for them at frequent enough intervals?<br>
><br>
><br>
> You subscribe to the events you're interested in with 'events'<br>
> <a href="http://wiki.freeswitch.org/wiki/Event_socket#event" target="_blank">http://wiki.freeswitch.org/wiki/Event_socket#event</a><br>
><br>
> There's no polling involved. FS will send all subscribed events through the<br>
> socket, you just need to receive them. Use select()/poll()/equivalent to<br>
> detect when data has arrived.<br>
><br>
> Since you already have xml_cdr working that would be the best place to<br>
> collect it, if you can add an extra DB insert in the handler.<br>
><br>
> -Steve<br>
><br>
><br>
> On 29 November 2012 11:58, Richard Gration <<a href="mailto:richgration@gmail.com">richgration@gmail.com</a>> wrote:<br>
>><br>
>> Hi,<br>
>><br>
>> Thanks for your reply. I was wondering ...<br>
>><br>
>> > If you listen to events then you should be able to reliably receive a<br>
>> > hangup<br>
>> > event containing the variables if you are still connected at that time.<br>
>><br>
>> ... how I listen for these events. Is it just a case of polling the<br>
>> socket for them at frequent enough intervals?<br>
>><br>
>> > If you want a 100% reliable method use CDRs.<br>
>> ><br>
>> > mod_xml_cdr can submit call CDRs to a webserver just after call hangup.<br>
>> > The<br>
>> > XML is verbose and will contain a full call history and all channel<br>
>> > variables. Because it's submitted ASAP you get the results in real time<br>
>> > and<br>
>> > reliable. If the module can't submit the CDRs it writes them to an error<br>
>> > folder on disk where you can resubmit them.<br>
>> ><br>
>> > Real time seems useful for your use-case, as your script would just need<br>
>> > to<br>
>> > check your DB whether the CDR had been submitted yet. The channel UUID<br>
>> > can<br>
>> > either be captured from events or specified in advance in the originate<br>
>> > (originate_uuid). There's a uuid api call to generate them for you. I'd<br>
>> > suggest looking at this method.<br>
>><br>
>> This is all great info, thanks :-) I'm capturing the uuid from the<br>
>> response from the originate command, that's no problem.<br>
>><br>
>> The box I'm doing this on is being a B2BUA for us at the moment. The<br>
>> CDRs are already being HTTP POSTed to a URL, I can't change that as<br>
>> our billing depends on it. I can see the channel variable coming<br>
>> though in the POST content, so maybe I can frob the CDR script to give<br>
>> me what I want.<br>
>><br>
>> Thanks again for the info.<br>
>><br>
>> Cheers,<br>
>> Rich<br>
>><br>
>> --<br>
>> Once our basic material needs are met - in my utopia, anyway - life<br>
>> becomes a perpetual celebration in which everyone has a talent to<br>
>> contribute. But we cannot levitate ourselves into that blessed<br>
>> condition by wishing it. We need to brace ourselves for a struggle<br>
>> against terrifying obstacles, both of our own making and imposed by<br>
>> the natural world. And the first step is to recover from the delusion<br>
>> that is positive thinking.<br>
>> -- Barbara Ehrenreich<br>
>><br>
>> _________________________________________________________________________<br>
>> Professional FreeSWITCH Consulting Services:<br>
>> <a href="mailto:consulting@freeswitch.org">consulting@freeswitch.org</a><br>
>> <a href="http://www.freeswitchsolutions.com" target="_blank">http://www.freeswitchsolutions.com</a><br>
>><br>
>> FreeSWITCH-powered IP PBX: The CudaTel Communication Server<br>
>> <a href="http://www.cudatel.com" target="_blank">http://www.cudatel.com</a><br>
>><br>
>> Official FreeSWITCH Sites<br>
>> <a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
>> <a href="http://wiki.freeswitch.org" target="_blank">http://wiki.freeswitch.org</a><br>
>> <a href="http://www.cluecon.com" target="_blank">http://www.cluecon.com</a><br>
>><br>
>> FreeSWITCH-users mailing list<br>
>> <a href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a><br>
>> <a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
>> UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
>> <a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
><br>
><br>
><br>
> _________________________________________________________________________<br>
> Professional FreeSWITCH Consulting Services:<br>
> <a href="mailto:consulting@freeswitch.org">consulting@freeswitch.org</a><br>
> <a href="http://www.freeswitchsolutions.com" target="_blank">http://www.freeswitchsolutions.com</a><br>
><br>
> FreeSWITCH-powered IP PBX: The CudaTel Communication Server<br>
> <a href="http://www.cudatel.com" target="_blank">http://www.cudatel.com</a><br>
><br>
> Official FreeSWITCH Sites<br>
> <a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
> <a href="http://wiki.freeswitch.org" target="_blank">http://wiki.freeswitch.org</a><br>
> <a href="http://www.cluecon.com" target="_blank">http://www.cluecon.com</a><br>
><br>
> FreeSWITCH-users mailing list<br>
> <a href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a><br>
> <a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
> UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
> <a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
><br>
<br>
<br>
<br>
--<br>
Once our basic material needs are met - in my utopia, anyway - life<br>
becomes a perpetual celebration in which everyone has a talent to<br>
contribute. But we cannot levitate ourselves into that blessed<br>
condition by wishing it. We need to brace ourselves for a struggle<br>
against terrifying obstacles, both of our own making and imposed by<br>
the natural world. And the first step is to recover from the delusion<br>
that is positive thinking.<br>
-- Barbara Ehrenreich<br>
<br>
_________________________________________________________________________<br>
Professional FreeSWITCH Consulting Services:<br>
<a href="mailto:consulting@freeswitch.org">consulting@freeswitch.org</a><br>
<a href="http://www.freeswitchsolutions.com" target="_blank">http://www.freeswitchsolutions.com</a><br>
<br>
FreeSWITCH-powered IP PBX: The CudaTel Communication Server<br>
<a href="http://www.cudatel.com" target="_blank">http://www.cudatel.com</a><br>
<br>
Official FreeSWITCH Sites<br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<a href="http://wiki.freeswitch.org" target="_blank">http://wiki.freeswitch.org</a><br>
<a href="http://www.cluecon.com" target="_blank">http://www.cluecon.com</a><br>
<br>
FreeSWITCH-users mailing list<br>
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
</div></div></blockquote></div><br></div>