#######################################
## Do Not Edit
## san2(at)linuxchannel.net
########################################
##
## php_accel.lib

phpaccelerator_install_preview() {
    #if [ "$foundphp_accelerator" != "0" -a "$foundapache" != "0" -a "$foundphp" != "0" ] ; then
    if [ "$foundphp_accelerator" != "0" ] ; then
        echo "${T_MD}[$i] ${PHPACCEL_V}${T_ME} install to [/usr/local/php]"

        i=$(($i+1))
    #else
    #    echo "*** Notice!!! Not found ${WORK}/php_accelerator-xxx.tgz"
    #    echo "*** so SKIP php_accelerator install"
    #    echo "*** Do you have TWO(2) php_accelerator-xxx.tgz ???"
        fi
}

phpaccelerator_config_v1() {

    a=";"
    b="; PHP-Accelerator(${PHPACCEL_V})"
    c="; WARNNING : does not work together will the Zend optimizer !!!!"
    d=";"
    e="zend_extension=\"${php_acceltarget}\""
    f="phpa = on"
    g="phpa.c0_size = 8"
    h="phpa.cache_dir = /tmp"
    i="phpa.c0_logging = on"
    j="phpa.c0_stats_check_period = 5m"
    k="phpa.c0_ttl = 12h"
    l=";;phpa.ignore_files = \"/index.php,/a/help.php\""
    m=";;phpa.ignore_dirs = \"/data/WWW/site1/,/cache/\""

    for line in "$a" "$b" "$c" "$d" "$e" "$f" "$g" "$h" "$i" "$j" "$k" "$l" "$m" ; do
        echo "$line" >> $phpinitarget
        addfile "Added in $phpinitarget : $line" $DONEFILE
    done
}

phpaccelerator_config_v2() {

    ## localhost key
    ##
    localhost_key=f5eaa9f7856d20312d755d6c29bc5d42

phpa_head_config=`cat << __EOP__
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; PHP-Accelerator Configurations ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; ********************************
; ***
; *** WARNNING : does not work together Zend optimizer !!!!
; ***
; *** PHP-Accelerator(${PHPACCEL_V})
; ***
; *** Auto configurations 'APMsh' shell script
; *** By $APMsh_by
; *** URL $APMsh_url
; ***
; *** Replace <key> to your 'ServerName' <key> of httpd.conf !!!!!!
; *** <key> was set to localhost('$localhost_key').
; ***
; ***    phpa.registration_key = $localhost_key
; ***
; *** see http://www.php-accelerator.co.uk/activate.php
; ***
; ********************************
;
zend_extension="$php_acceltarget"
;
;
__EOP__`

OIFS=$IFS
IFS='
'

    echo "" >> $phpinitarget
    echo "" >> $phpinitarget

    addfile "------------- Added in $phpinitarget : ---------------------" $DONEFILE

    for m in $phpa_head_config ; do
        echo "$m" >> $phpinitarget
        addfile "$m" $DONEFILE
    done

    phpa_body_config=`cat "${WORK}/${PHPACCEL_V}/CONFIGURATION" 2>/dev/null | egrep "^(phpa|;)"`

    for n in $phpa_body_config ; do
        if [ X$(echo "$n" | grep "^phpa") != "X" ] ; then
            n=`echo "$n" | sed -e "s/<key>/$localhost_key/" \
                -e "s/^phpa\.registration_keys_file/;phpa.registration_keys_file/" \
                -e "s/^phpa\.ignore_/;phpa.ignore_/" \
                -e "s/^phpa\.shm_ignore_/;phpa.shm_ignore_/"`

            echo ";" >> $phpinitarget
            echo "$n" >> $phpinitarget
            echo "" >> $phpinitarget
            addfile "$n" $DONEFILE
        else
            echo "$n" >> $phpinitarget
        fi
    done

    echo ";" >> $phpinitarget
    echo "; End of PHP-Accelerator Configurations ----------------------------------" >> $phpinitarget
    addfile "------------- Added in $phpinitarget : ---------------------" $DONEFILE

    IFS=$OIFS

    #phpa.registration_key = <key>
    #phpa.registration_keys_file = <file>
    #phpa.show_registration_warnings = on
    #phpa = on
    #phpa.tweaks = on
    #phpa.cache_dir = /tmp
    #phpa.file_perms = 400
    #phpa.ignore_files = "/index.php,/a/help.php"
    #phpa.ignore_dirs = "/data/WWW/site1/,/cache/"
    #phpa.shm_size = 8
    #phpa.shm_key = 0xc0deb00
    #phpa.shm_perms = 664
    #phpa.shm_release_at_exit = on
    #phpa.shm_logging = on
    #phpa.shm_stats_check_period = 5m
    #phpa.shm_ttl = 12h
    #phpa.shm_ignore_files = "/index.php,/a/help.php"
    #phpa.shm_ignore_dirs = "/data/WWW/site1/,/cache/"
    #phpa.shm_max_processes = 512
}

## php_accelerrator config
## 2001.12.12
##
phpaccelerator_config() {
    check_tmp_phpa_v=${PHPACCEL_V#*.}

    if [ X$(echo "$check_tmp_phpa_v" | grep "^1") != "X" ] ; then
        check_zendopt=1
    elif [ X$(echo "$check_tmp_phpa_v" | grep "^2") != "X" ] ; then
        check_zendopt=2
    fi

    if [ X"$check_zendopt" != "X" ] ; then
        check_zendopt_install
        eval phpaccelerator_config_v${check_zendopt}
    fi
}