Hi all,
Have been back on the php trail again recently. On problem I’ve had is to do with executing a certain piece of code every 20 seconds. One way in which I was doing it was:
[code lang="php"]
startTime = time();
while(true)
{ endTime = time();
if(endTime - startTime > 20)
{ startTime = time();
//Code
}
}
[/code]
This however is quite harsh on the CPU. If came up with a better and more obvious way to do time-based looping
[code lang="php"]
while(true)
{ sleep(20);
//Code
}
[/code]
This loops around every 20 seconds and runs the piece of code and is much nicer on the CPU
I’ve been using PHP AGI which hooks into the Asterisk Extensions.conf dialplan.
One of the other problems I’ve been having is that the php scripts weren’t being killed by asterisk when a user hangs up in the middle of the call.
The solution is to register a handler to react to the hangup event
[code lang="php"]
if(function_exists('pcntl_signal'))
{ pcntl_signal(SIGHUP,'sig_handler');
}
[/code]
This registers the function sig_handler to be run when a hangup is detected within the php script execution
[code lang="php"]
function sig_handler($signo)
{ //Other code, CDR and closing MYSQL conns
exit(0);
}
[/code]
The exit closes the php script thus freeing up the CPU.
I ssh’ed onto my iTouch yesterday. I followed the instructions here http://hacktheiphoneitouch.blogspot.com/2007/12/installing-ssh-client-on-112-iphone.html for the MAC, works nicely. Put on Apache and PHP, not tested them as of yet but I’m sure they’ll work nicely as a simple webserver. Haven’t upgraded from 1.1.2 as of yet couldn’t be bothered jailbreaking again but when 1.1.3 is jailbroken out I’ll consider upgrading. Want to get the mail, stocks etc new apps at some stage……free preferably. Thinking of looking for a ColdFusion server for the iTouch, major long shot but would be hilarious if I got it working!
