Apc_fetch not working

software development

#1

Hey,

Im trying to get my apc_fetch to work, to monitor my upload progres… But there are a couple of problems.

1 install apc --> Solved with a install script

cript for a minimal PHP 6.3.x install with APC
#
#- Prompts for the domain to build for
#- PHP configure line contains only valid PHP5 options
#- Displays colourful status messages
#- Many build messages, which aren't helpful to most people, are now suppressed
#- Procedurised, making it cleaner and easier to follow
#
#The only things you may want to change in here are marked with "@todo"s
#
#Derived form the original PHP 5.3 install script at
#http://wiki.dreamhost.com/Installing_PHP5
#
#@author Dan Bettles <dan@danbettles.net>

#Exit on error
set -e

clear

echo -n "Enter the domain for which you want to build PHP and press [ENTER]: "
read DOMAIN

#===============================================================================

#@todo Update versions, if necessary
M4="m4-1.4.13"
AUTOCONF="autoconf-2.65"
CURL="curl-7.19.7"
PHP="php-5.3.4"
APC="APC-3.1.3p1"

BUILD_DIR="$HOME/build"
DOWNLOADS_DIR="$HOME/downloads"
WEB_ROOT="$HOME/$DOMAIN"

CGI_BIN_DIR="$WEB_ROOT/cgi-bin"
PHP_INI="$CGI_BIN_DIR/php.ini"

HTACCESS="$WEB_ROOT/.htaccess"

PHP_BASE_DIR="$HOME/$PHP"
PHP_BIN_DIR="$PHP_BASE_DIR/bin"
PHP_EXTENSIONS_DIR="$PHP_BASE_DIR/extensions"

#@todo Alter features, if necessary
PHP_FEATURES="\
--bindir=$PHP_BIN_DIR \
--with-config-file-path=$CGI_BIN_DIR \
--without-pear \
--with-curl=$PHP_BASE_DIR \
--with-gd \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-zlib-dir=/usr \
--with-freetype-dir=/usr \
--enable-gd-native-ttf \
--enable-mbstring \
--with-mysql \
--with-mysqli \
--with-pdo-mysql \
--with-xsl \
--enable-zip \
--disable-hash \
--disable-posix \
--disable-xmlwriter \
--disable-xmlreader"

#===============================================================================

#@param string $1 Message
function echoL1 () {
    echo -e "\n\033[1;37;44m$1\033[0;0;0m\n"
}

#@param string $1 Message
function echoL2 () {
    echo -e "\n\033[0;37;44m$1\033[0;0;0m\n"
}

#@param string $1 URL
#@param string $2 Output directory
function downloadTo () {
    wget -c $1 --directory-prefix=$2
}

#@param string $1 TAR filename
#@param string $2 Output directory
function untarTo () {
    cd $2
    tar -xzf $1
    cd -
}

#@param string $1 Source directory
#@param string $2 Output directory
#@param string $3 configure arguments
function configureAndMake () {
    cd $1
    COMMAND="./configure --quiet --prefix=$2 $3"
    echo "$COMMAND"
    eval $COMMAND
    make --quiet 
    cd -
}

#@param string $1 Source directory
#@param string $2 Output directory
#@param string $3 configure arguments
function makeAndInstall () {
    configureAndMake $1 $2 "$3"
    cd $1
    make install --quiet 
    cd -
}

#@param string $1 Directory
function mkdirClean () {
    rm -rf $1
    mkdir -p $1
}

#@param string $1 Message
function echoWarning () {
    echo -e "\n\033[1;37;41m$1\033[0;0;0m\n"
}

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

export PATH="$PATH:$PHP_BIN_DIR"

echoL1 "-> DOWNLOADING..."

mkdirClean $BUILD_DIR 

echoL2 "--> Downloading $M4..."
downloadTo "http://ftp.gnu.org/gnu/m4/$M4.tar.gz" $DOWNLOADS_DIR
untarTo "$DOWNLOADS_DIR/$M4.tar.gz" $BUILD_DIR 

echoL2 "--> Downloading $AUTOCONF..."
downloadTo "http://ftp.gnu.org/gnu/autoconf/$AUTOCONF.tar.gz" $DOWNLOADS_DIR
untarTo "$DOWNLOADS_DIR/$AUTOCONF.tar.gz" $BUILD_DIR 

echoL2 "--> Downloading $CURL..."
downloadTo "http://curl.haxx.se/download/$CURL.tar.gz" $DOWNLOADS_DIR
untarTo "$DOWNLOADS_DIR/$CURL.tar.gz" $BUILD_DIR 

echoL2 "--> Downloading $PHP..."
downloadTo "http://www.php.net/get/$PHP.tar.gz/from/this/mirror" $DOWNLOADS_DIR
untarTo "$DOWNLOADS_DIR/$PHP.tar.gz" $BUILD_DIR 

echoL2 "--> Downloading $APC..."
downloadTo "http://pecl.php.net/get/$APC.tgz" $DOWNLOADS_DIR
untarTo "$DOWNLOADS_DIR/$APC.tgz" $BUILD_DIR 

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

echoL1 "-> BUILDING..."

mkdir -p $PHP_BASE_DIR 

echoL2 "--> Building $M4..."
makeAndInstall "$BUILD_DIR/$M4" $PHP_BASE_DIR

echoL2 "--> Building $AUTOCONF..."
makeAndInstall "$BUILD_DIR/$AUTOCONF" $PHP_BASE_DIR

echoL2 "--> Building $CURL..."
makeAndInstall "$BUILD_DIR/$CURL" $PHP_BASE_DIR "--enable-ipv6 --enable-cookies\
 --enable-crypto-auth" 

echoL2 "--> Building $PHP..."
#Fixes compile error
export EXTRA_LIBS="-lresolv"
makeAndInstall "$BUILD_DIR/$PHP" $PHP_BASE_DIR "$PHP_FEATURES" 

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

echoL1 "-> INSTALLING PHP..."

mkdir -p -m 0755 $CGI_BIN_DIR
cp "$PHP_BIN_DIR/php-cgi" "$CGI_BIN_DIR/php.cgi"
cp "$BUILD_DIR/$PHP/php.ini-production" $PHP_INI

mkdir -p $PHP_EXTENSIONS_DIR

echoL2 "--> Building $APC..."
APC_SOURCE_DIR="$BUILD_DIR/$APC"
cd $APC_SOURCE_DIR
$PHP_BIN_DIR/phpize
configureAndMake $APC_SOURCE_DIR $PHP_BASE_DIR "--enable-apc --enable-apc-mmap\
 --with-php-config=$PHP_BIN_DIR/php-config" 
cp modules/apc.so $PHP_EXTENSIONS_DIR
echo "extension=$PHP_EXTENSIONS_DIR/apc.so" >> $PHP_INI
cd -

#-------------------------------------------------------------------------------

if [ -f $HTACCESS ]; then
    HTACCESS_NEW="$HTACCESS.old"
    mv $HTACCESS $HTACCESS_NEW
    echoWarning "--> Moved $HTACCESS to $HTACCESS_NEW"
fi

#The backslash prevents a newline being inserted at the start
HTACCESS_CONTENT="\
Options +ExecCGI
AddHandler php-cgi .php
Action php-cgi /cgi-bin/php.cgi

#Deny access to the PHP CGI executable and config files
<FilesMatch \"^php5?\.(cgi|ini)$\">
    Order Deny,Allow
    Deny from All
    Allow from env=REDIRECT_STATUS
</FilesMatch>"

#Preserve newlines in the content by quoting the variable name
echo "$HTACCESS_CONTENT" >> $HTACCESS

echoL2 "--> Created $PHP_INI"

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

rm -rf $BUILD_DIR

echo -n "Delete the downloads directory? (yes / no): "
read DELETE_DOWNLOADS_DIR

if [ $DELETE_DOWNLOADS_DIR = "yes" ]; then
    rm -rf $DOWNLOADS_DIR
fi

echoL1 "DONE"

exit 0

This enabled my apc with the install, all is fine. I saw that fast cgi was working.

ive added “apc.rfc1867 = 1;” to my php.ini

no change… my phpinfo reported:

Version 	3.1.3p1
MMAP Support 	Enabled
MMAP File Mask 	no value
Locking type 	pthread mutex Locks
Revision 	$Revision: 286798 $
Build Date 	Dec 17 2010 05:09:11

Directive	Local Value	Master Value
apc.cache_by_default	On	On
apc.canonicalize	On	On
apc.coredump_unmap	Off	Off
apc.enable_cli	Off	Off
apc.enabled	On	On
apc.file_md5	Off	Off
apc.file_update_protection	2	2
apc.filters	no value	no value
apc.gc_ttl	3600	3600
apc.include_once_override	Off	Off
apc.lazy_classes	Off	Off
apc.lazy_functions	Off	Off
apc.max_file_size	1M	1M
apc.mmap_file_mask	no value	no value
apc.num_files_hint	1000	1000
apc.preload_path	no value	no value
apc.report_autofilter	Off	Off
apc.rfc1867	On	On
apc.rfc1867_freq	0	0
apc.rfc1867_name	APC_UPLOAD_PROGRESS	APC_UPLOAD_PROGRESS
apc.rfc1867_prefix	upload_	upload_
apc.rfc1867_ttl	3600	3600
apc.shm_segments	1	1
apc.shm_size	30	30
apc.stat	On	On
apc.stat_ctime	Off	Off
apc.ttl	0	0
apc.use_request_time	On	On
apc.user_entries_hint	4096	4096
apc.user_ttl	0	0
apc.write_lock	On	On

still not working GRRRR but then i found that i should add this line to the .ini file “apc.mmap_file_mask=”/home/reneweteling/tmp";" but when i do this i get an 500 error. the file exists and is 777 (overkill but im trouble shooting)

please help im getting pretty annoyed. Please excuse my english im dutch.

thanks in advance!!


#2

There’s a somewhat disappointing note in the apc_fetch documentation that may explain what’s happening:

[quote]nospam dot list at unclassified dot de
20-Nov-2007 11:06

This function is often cited related to file upload tracking with PHP 5.2. So I thought this is a good place to put a warning.

If you setup PHP with FastCGI, you’ll probably run into trouble using this function to get any information about a running upload. At least in my case, every HTTP request is handled by a different PHP process. I could track it with the getmypid() function, which returned a different value upon every request, but only from a limited set. Also, apc_cache_info() gave me all upload_* entries that were created in that process. So when the upload was initially catched by one PHP process, all progress updates must be fetched from the same process, too, because APC cache information does not seem to be shared across multiple processes handling that domain/virtual host. But that’s impossible to tell because PHP has its own load management and serves every request by an arbitrary process.

So in short: When using FastCGI and multiple PHP processes (recommended for performance reasons), you cannot use APC upload tracking. You’ll only get a status update every few requests.[/quote]