PHP works with cache?

Asked

Viewed 677 times

9

I am noticing that my application is occurring some error, or else my browser is always storing cache, even if I perform the cleaning. I have a file .php and in it contain the function loadEvent, responsible for conducting consultations select. I happen to change the instruction select to bring a different result, save the file .php, update the browser, but the result is still coming from select previous. After a minute, without me doing anything in the code, the browser starts to interpret the select altered. So I ask, is there any possibility of .php work with caching in this situation?

  • oisw be cached from your browser, php , from apache. This test you do is online?

  • localhost, on my machine. I removed all browser cache.

  • most likely that the platform you are programming ta by caching same or your browser. usually the ones who cache in apache are the big servers like Locaweb and Uol to optimize access

  • I tell you, it’s not browser caching.

  • so this in your application would have to see in it c it saves cookie or if there is some folder saving cached php files

1 answer

8


PHP does not use cache by default, it can be done using the function header();, but as you said you removed the browser cache and still continued to display the same results then the problem must be some extension of Bytecode (read also about just-in-time (JIT))

PHP is an interpreted language, meaning for each request and each person accessing the script will have to be interpreted, the extensions Bytecode "save" the various "interpretations" of the script in "memory", a "compiled" version"of the code, making the script not need to be completely processed, ie only will process some things, this often brings advantages in the running time of a script and lower consumption of the server resources which is a great 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)

  • APC (not to be confused with Apcu)

    Can installed since PHP 5.1 using PECL

  • Xcache

    Maintained by the same lighttpd group, it can be installed in PHP 5.1, 5.2, 5.3, 5.4, 5.5 and 5.6

That is the moment 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'], this because the language was compiled for probably a intermediate language (does not need to be a complete language), so dynamic values continue to change, but the script script does not.

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

If you are in development environment it is recommended to turn off the extension on php.ini commenting the extensions with dot and comma.

If you are in development and using built-in APC features you can try switching to Apcu or by memcache

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

    ;zend_extension=opcache.so
    

    If it is Windows:

    ;zend_extension=php_opcache.dll
    

    You can do it too:

    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 is Windows:

    ;extension=php_apc.dll
    

    You can do it too:

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

    ;extension=xcache.so
    

    If it is Windows:

    ;extension=php_xcache.dll
    
  1. Note: The HHVM already has its own JIT
  2. Note: The compilers bytecode although it takes a few seconds to clear the "cache" of "compiled" versions is still great in production environment, if updating server files is likely to have to restart so that updates are affected immediately.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.