Does PHP work with cache?

9

I'm noticing that my application is experiencing some error, or else my browser is always caching, even though I'm performing the cleanup. I have a .php file and contain the loadEvent function, which is responsible for doing select queries. It turns out that I change the select statement to bring a different result, save the file .php , update the browser, but the result still comes from the previous select . After a minute, without doing anything in the code, the browser interprets% changed%. So I ask: Is there any possibility of select working with cache in this situation?

    
asked by anonymous 21.11.2016 / 11:30

1 answer

9

PHP does not use cache by default, it can be done using the header(); function, but as you said you removed the browser cache and even then continued to display the same results then the problem should be some extension of <

Bytecode (also read on just-in-time (JIT)

PHP is an interpreted language, ie every request and every person accessing the script will have to be interpreted, the extensions < in> Bytecode "save" the various "interpretations" of the script in the "memory", a "compiled" version of the code, causing the script not to be completely processed, process a few things, this often brings advantages in running a script and less time consuming server resources which is a big advantage for the production environment .

Examples of bytecode extensions for PHP:

  • Opcache

    Default in php 5.5 onwards and can only be installed in versions 5.2, 5.3 and 5.4 through PECL ) / p>

  • APC (not to be confused with APCu )

    Can be installed from PHP 5.1 using PECL

  • Xcache

    It is supported by the same group that maintains lighttpd, can be installed in PHP 5.1, 5.2, 5.3, 5.4, 5.5 and 5.6

That is when you change the code as:

$stmt = mysqli_prepare($link, 'SELECT foo FROM bar WHERE foo=?');
mysqli_stmt_bind_param($stmt, 's', $_GET['foo']);

For something like:

$stmt = mysqli_prepare($link, 'SELECT foo,nome,sobrenome FROM bar WHERE foo=?');
mysqli_stmt_bind_param($stmt, 's', $_GET['foo']);

Depending on the extension the script will still work as first, the only thing that changes the behavior is $_GET['foo'] , because the language was compiled for probably an intermediate language (it does not have to be a complete language ), so the dynamic values continue to change, but the script script does not.

The extension itself usually detects changes, but usually takes a few seconds or will require or restart the Apache server (ngnix, lighttp, etc.).

If you are in development environment it is recommended that you disconnect the extension in php.ini by commenting extensions with a semicolon.

  

If you are developing and using internal APC features you can try switching to APCu or memcache

  • To turn off Opcache you can comment on lines like this (if it's Unix-like):

    ;zend_extension=opcache.so
    

    If it's Windows:

    ;zend_extension=php_opcache.dll
    

    You can also do this:

    opcache.enabled=0
    
  • To turn off the APC you can comment on lines like this (if it's Unix-like):

    ;extension=apc.so
    

    If it's Windows:

    ;extension=php_apc.dll
    

    You can also do this:

    apc.enabled=0
    
  • To turn off Xcache you can comment on lines like this (if it's Unix-like):

    ;extension=xcache.so
    

    If it's Windows:

    ;extension=php_xcache.dll
    
  
  • Note: HHVM already has JIT itself
  •   
  • Note: The bytecode compilers although it takes a few seconds to clear the "compiled" versions' cache yet is great in the production environment if you update the server files it is likely to have to restart for updates to be affected immediately.
  •   
        
    21.11.2016 / 11:56