Results 1 to 10 of 10

Thread: PHP-CLI for AGI and Exiting Cleanly (Process Control Needed)

  1. #1
    rpurinton Guest

    Default PHP-CLI for AGI and Exiting Cleanly (Process Control Needed)

    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 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.


  2. #2
    agauthier Guest

    Default PHP-CLI for AGI

    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.

  3. #3
    rpurinton Guest


    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.

  4. #4
    agauthier Guest

    Default PHP-CLI for AGI .mk file

    The file that needs to be changed is

    Then add the -- switch to

  5. #5
    rpurinton Guest


    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:


    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/' '--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/' '--enable-gettext' '--with-gettext=/root/freepbx-mysql/' '--enable-iconv' '--with-iconv=/root/freepbx-mysql/' '--with-layout=GNU' '--enable-fastcgi' '--enable-cli' '--enable-ctype' '--enable-magic-quotes' '--enable-memory-limit' '--enable-libxml' '--with-libxml-dir=/root/freepbx-mysql/' '--enable-xml' '--enable-mysq' '--with-mysql=/root/freepbx-mysql/' '--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 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/ MYSQL_LIBS -L/root/freepbx-mysql/ -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_persist entUnlimitedUnlimitedmysql.trace_modeOffOff


    pcntl supportenabled

    Any help on this? Should I change that configure option to --enable-mysql? It appears this is how the comes default. as it even shows here:

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

  6. #6
    rpurinton Guest


    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.

  7. #7
    rpurinton Guest


    AGI scripts now terminate cleanly with --enable-pcntl

  8. #8
    rpurinton Guest


    The fix I applied for MySQL did not withstand a reboot. What would be the proper way to fix this permanently on the images?

  9. #9
    agauthier Guest

    Default mysql

    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

  10. #10
    skar Guest

    Default pcntl added in trunk

    The flag recommended by rpurinton has been added to the svn trunk code of FreePBX on PADS as of revision number 18489.

    Thanks for the tip rpurinto.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts