downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

apc_dec> <apc_clear_cache
[edit] Last updated: Fri, 25 May 2012

view this page in

apc_compile_file

(PECL apc >= 3.0.13)

apc_compile_fileStocke un fichier dans le cache, en évitant tous les filtres

Description

mixed apc_compile_file ( string $filename [, bool $atomic = true ] )

Stocke un fichier dans le cache, en évitant tous les filtres.

Liste de paramètres

filename

Chemin complet ou relatif vers un fichier PHP qui sera compilé et stocké dans le cache.

Valeurs de retour

Cette fonction retourne TRUE en cas de succès ou FALSE si une erreur survient.

Voir aussi

  • apc_bin_dumpfile() - Envoi une sortie binaire des fichiers fournis et des variables utilisateur vers un fichier spécifique
  • apc_bin_loadfile() - Charge une sortie binaire depuis un fichier dans le cache fichiers ou utilisateur d'APC


apc_dec> <apc_clear_cache
[edit] Last updated: Fri, 25 May 2012
 
add a note add a note User Contributed Notes apc_compile_file
highcode at yahoo dot com 06-Aug-2009 01:09
if your goal is to pre-compile PHP script into bytecode and then transparently loaded the script, better use monas, its a free php extension to encode/decode PHP 4 and PHP 5. check it at http://ombudi.com, i've try using it to encode phpmyadmin and works nicely
Glen 31-Mar-2009 11:44
There are reasons to use this routine.  I can think of two:

- a busy website will have multiple web servers, and before one is brought online (via load balancer), the cache is built.  This prevents problems of having too many cache misses in a short period on your entire code base, which could be massive, and cause problems.

- a website where the apc.stat flag is set to zero.  That setting provides significant performance savings because no 'stat' needs to be performed on PHP code files.  But they are not automatically rebuilt when changed.  So what do you do when your code changes?  Restart Apache, or manually clearing the APC cache with apc_clear_cache() - but both will clear the entire cache.  There may be cases where it is much better to recompile select files instead.  Some sites store data (that rarely changes) in PHP code to make good use of the opcode cache, updating that file and selectively compiling it would make writes efficient too.
A.R. 22-Mar-2009 04:15
It should be noted, that the above suggestion to "compile your entire project", or for any web developer to ever call this apc_compile_file function at all, is superfluous, because APC will automatically compile pages for you on demand. This function does not do anything useful.

I had actually avoided installing APC for a long time because I thought it would be very complex, partly because of this manual page which tells you how to compile but doesn't tell you how to execute a compiled page.

After installing APC, you can tell if it's working, by adding this to one of your webpages:

<?php
   
echo("<pre>");
   
print_r(apc_cache_info());
    echo(
"</pre>");
?>

Run this before and after hitting a few pages on the site, to see the compiled files automatically show up in the list.

Again, there is no need to ever call apc_compile_file explicitly. This function is probably available for some sort of very advanced use.
Andrea Giammarchi 15-Feb-2008 04:40
This is a simple way to cache a project entirely.

<?php // apc_compile_dir.php
function apc_compile_dir($root, $recursively = true){
   
$compiled   = true;
    switch(
$recursively){
        case   
true:
            foreach(
glob($root.DIRECTORY_SEPARATOR.'*', GLOB_ONLYDIR) as $dir)
               
$compiled   = $compiled && apc_compile_dir($dir, $recursively);
        case   
false:
            foreach(
glob($root.DIRECTORY_SEPARATOR.'*.php') as $file)
               
$compiled   = $compiled && apc_compile_file($file);
            break;
    }
    return 
$compiled;
}
?>

This is an example on how to use the function to compile your project.
<?php
echo    '<pre>'.PHP_EOL;
if(
function_exists('apc_compile_file')){
   
define('APC_CLEAR_CACHE',           true);
   
define('APC_COMPILE_RECURSIVELY',   true);
   
define('APC_COMPILE_DIR',           '.');
    require
'apc_compile_dir.php';
    echo   
'APC Directory Compiler '.gmdate('Y-m-d H:i:s').PHP_EOL;
    echo   
PHP_EOL.'-------------------------'.PHP_EOL;
    if(
APC_CLEAR_CACHE){
        echo    (
apc_clear_cache() ? 'Cache Cleaned' : 'Cache Not Cleaned').PHP_EOL;
       
var_dump(apc_cache_info());
        echo   
PHP_EOL.'-------------------------'.PHP_EOL;
    }
    echo   
'Runtime Errors'.PHP_EOL;
    echo    (
apc_compile_dir(APC_COMPILE_DIR, APC_COMPILE_RECURSIVELY) ? 'Cache Created' : 'Cache Not Created').PHP_EOL;
    echo   
PHP_EOL.'-------------------------'.PHP_EOL;
   
var_dump(apc_cache_info());
}
else
    echo   
'APC is not present, nothing to do.'.PHP_EOL;
echo   
'</pre>';
?>

 
show source | credits | stats | sitemap | contact | advertising | mirror sites