PDA

View Full Version : PHP-CLI for AGI and Exiting Cleanly (Process Control Needed)



rpurinton
09-25-09, 11:58 AM
According to PHP/AGI best practices for exiting cleanly...


On hangup from the caller, Asterisk will kill your script with SIGHUP; you can use pcntl_signal (http://ca.php.net/manual/en/function.pcntl_signal.php) to run a user-defined function at this time.


pcntl_signal(SIGHUP, "agi_hangup_handler");
function agi_hangup_handler($signo) {
//this function is run when Asterisk kills your script ($signo is always 1)
//close file handles, write database records, etc.
__

According to PHP docs, for pcntl_signal to be available:

Process Control support in PHP is not enabled by default. You have to compile the CGI or CLI version of PHP with --enable-pcntl configuration option when compiling PHP to enable Process Control support.

Is there anyway I can recompile the CLI version of PHP on a live PIKA without having to go back to PADS to make all new images to have this feature enabled?

Without adding this signal handler, there is no way for an AGI/PHP script to clean up or continue processing after the caller hangs up, the script is just killed.

Thanks

agauthier
09-25-09, 12:11 PM
Currently, the only way to update this is through PADS.
Out of curiosity, are you using the FreePBX distribution for Warp?
This type of flag might be good to enable for the next version of FreePBX.

rpurinton
09-25-09, 01:30 PM
We are running the PIKA with our own blend of freepbx using mysql. Our images were based on PIKA's very first release of FreePBX with MySQL.

I agree this sounds like it should definetely be turned on for this purpose.

agauthier
09-25-09, 02:26 PM
The file that needs to be changed is
<PADS_DIR>/package/php/php.mk

Then add the -- switch to
PHP_CONFIGURE_OPTS

rpurinton
09-28-09, 11:22 AM
I have done this then ran

make php-dirclean
make php
make image

I have loaded the images on a WARP box and found that PHP is unable to connect to MySQL. The mysqld is running, and I can connect to it using the asterisk username and password from the command prompt, but when accessing the FreePBX gui, the error is presented:

FATAL ERROR

DB Error: connect failed


When I go for a more specific reason I get:
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

I find no file in /tmp/ named mysql.sock

When i run a script that executed phpInfo();

I do see:

Configure Command './configure' '--host=_____pc-linux' '--target=_____pc-linux' '--program-prefix=' '--prefix=/root/freepbx-mysql/2.0.0.94/build_warp/root/usr' '--with-config-file-path=/etc' '--with-config-file-scan-dir=/etc/php.d' '--disable-all' '--disable-debug' '--with-pic' '--disable-rpath' '--enable-pcntl' '--enable-curl' '--with-curl=/root/freepbx-mysql/2.0.0.94/build_warp/root/usr' '--enable-gettext' '--with-gettext=/root/freepbx-mysql/2.0.0.94/build_warp/root/usr' '--enable-iconv' '--with-iconv=/root/freepbx-mysql/2.0.0.94/build_warp/root/usr' '--with-layout=GNU' '--enable-fastcgi' '--enable-cli' '--enable-ctype' '--enable-magic-quotes' '--enable-memory-limit' '--enable-libxml' '--with-libxml-dir=/root/freepbx-mysql/2.0.0.94/build_warp/root/usr' '--enable-xml' '--enable-mysq' '--with-mysql=/root/freepbx-mysql/2.0.0.94/build_warp/root/usr' '--enable-eaccelerator' '--disable-ipv6' '--enable-session' '--enable-pdo' '--with-pcre-regex' '--enable-posix' '--enable-pear' '--with-pear=/usr/share/pear' '--with-tags='

I'm noticing the "--enable-mysq" and wondering if that should be --enable-mysql however farther down the page:

mysql

MySQL SupportenabledActive Persistent Links 0 Active Links 0 Client API version 5.1.30 MYSQL_MODULE_TYPE external MYSQL_SOCKET /tmp/mysql.sock MYSQL_INCLUDE -I/root/freepbx-mysql/2.0.0.94/build_warp/root/usr/include/mysql MYSQL_LIBS -L/root/freepbx-mysql/2.0.0.94/build_warp/root/usr/lib -lmysqlclient
DirectiveLocal ValueMaster Valuemysql.allow_persistentOnOnmysql.connect_timeo ut6060mysql.default_hostno valueno valuemysql.default_passwordno valueno valuemysql.default_portno valueno valuemysql.default_socketno valueno valuemysql.default_userno valueno valuemysql.max_linksUnlimitedUnlimitedmysql.max_pe rsistentUnlimitedUnlimitedmysql.trace_modeOffOff

pcntl

pcntl supportenabled

Any help on this? Should I change that configure option to --enable-mysql? It appears this is how the php.mk comes default. as it even shows here:
http://svn.pikatech.com/pads/addons/branches/freepbx-mysql/packages/patches/php/php.mk

I'm not sure where to from here. I have recompiled and reinstalled twice.

rpurinton
09-28-09, 11:34 AM
Resolved... checked out /etc/my.cnf to find the location of the mysql.sock on the PIKA...

fixed the problem with
ln -s /persistent2/mysql/usr/var/mysql.sock /tmp/mysql.sock

I'm not sure why this problem arose after just changing that configuration option and rebuilding. Will retest my other AGI scripts now that pcntl is enabled.

rpurinton
09-28-09, 03:32 PM
AGI scripts now terminate cleanly with --enable-pcntl

rpurinton
09-28-09, 04:02 PM
The fix I applied for MySQL did not withstand a reboot. What would be the proper way to fix this permanently on the images?

agauthier
09-28-09, 04:09 PM
if you check /etc you should notice that /etc/my.cnf points to /persistent/etc/my.cnf

You need to edit the file in /persistent/etc/my.cnf

skar
10-05-09, 10:17 AM
The flag recommended by rpurinton has been added to the svn trunk (http://svn.pikatech.com/pads/addons/trunk/freepbx-mysql/) code of FreePBX on PADS as of revision number 18489.

Thanks for the tip rpurinto.

Skar (http://twitter.com/skar_pikawarp)