1

I have a LAMP system on Ubuntu 14.04

I have made changes in the php.ini at the path /etc/php5/apache2/php.ini I have made the following changes in php.ini

opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=120

The reason I put opcache.enable_cli=1 is because i was getting the following error in php -i

Opcode Caching => Disabled
Optimization => Disabled
Startup Failed => Opcode Caching is disabled for CLI

opcache.enable => On => On
opcache.enable_cli => Off => Off

After puting opcache.enable_cli=1, I get the following in php -i

Zend OPcache

Opcode Caching => Up and Running
Optimization => Enabled
Startup => OK
Shared memory model => mmap
Cache hits => 0
Cache misses => 0
Used memory => 10707944
Free memory => 123509784
Wasted memory => 0
Cached scripts => 0
Cached keys => 0
Max keys => 3907
OOM restarts => 0
Hash keys restarts => 0
Manual restarts => 0

Directive => Local Value => Master Value
opcache.blacklist_filename => no value => no value
opcache.consistency_checks => 0 => 0
opcache.dups_fix => Off => Off
opcache.enable => On => On
opcache.enable_cli => On => On
opcache.enable_file_override => Off => Off
opcache.error_log => no value => no value
opcache.fast_shutdown => 1 => 1
opcache.file_update_protection => 2 => 2
opcache.force_restart_timeout => 180 => 180
opcache.inherited_hack => On => On
opcache.interned_strings_buffer => 8 => 8
opcache.load_comments => 1 => 1
opcache.log_verbosity_level => 1 => 1
opcache.max_accelerated_files => 2500 => 2500
opcache.max_file_size => 0 => 0
opcache.max_wasted_percentage => 5 => 5
opcache.memory_consumption => 128 => 128
opcache.optimization_level => 0xFFFFFFFF => 0xFFFFFFFF
opcache.preferred_memory_model => no value => no value
opcache.protect_memory => 0 => 0
opcache.restrict_api => no value => no value
opcache.revalidate_freq => 90 => 90
opcache.revalidate_path => Off => Off
opcache.save_comments => 1 => 1
opcache.use_cwd => On => On
opcache.validate_timestamps => On => On

Opcache is running but it is not caching anything. After a page loads for the first time and then I refresh the page within 90 seconds I see a different page

  • What do you mean you see a different page? Opcode caches don't cache the HTML output, they cache the PHP opcodes. If your database contents change, the page will change. – ceejayoz Aug 11 '15 at 15:16
  • Thanks for your reply ceejayoz. You have to pardon me since I am new to php and caches. So Opcache will not cache html output? What exactly is PHP opcodes? I have a database with 3 million rows with different categories which a user sees in different php pages. I have an RSS feed which adds data in the database every 1 hour. So what is the way to cache html pages? – Jayesh Duggal Aug 11 '15 at 15:22
  • See http://stackoverflow.com/questions/4821978/choosing-a-php-caching-technique-output-caching-into-files-vs-opcode-caching http://stackoverflow.com/questions/3787125/how-to-cache-dynamic-php-page as examples of various approaches. There are many ways to cache HTML output in PHP. You'll need to implement one - there are many classes and existing solutions for storing to files, memory stores like Redis/memcached, databases, etc. – ceejayoz Aug 11 '15 at 15:27
  • So what are hits and misses numbers in Opcache – Jayesh Duggal Aug 11 '15 at 16:01
  • The APC opcode cache has some functionality that can be used to do output caching (http://php.net/manual/en/function.apc-fetch.php sort of stuff) but you'd have to implement it yourself with those functions. Cache/hit numbers I believe refer to both those calls and hits/misses to the opcode cache itself. i.e. the first time `index.php` is accessed it'll be a miss, but subsequent accesses would be hits. When you change the file, the opcode cache notices and you'd have another miss. – ceejayoz Aug 11 '15 at 16:35

1 Answers1

1

You're misunderstanding what opcache is. PHP files are just plain text. They're not machine code. So PHP has to parse that text and generate machine code (operation code, or opcode for short). Once it has that opcode, it can then run your program.

Opcache simply stores the opcodes. It helps save overhead when the underlying code isn't changing a lot.

What you're talking about is something like output caching, where the web server stores what it sends to the clients.

Machavity
  • 30,841
  • 27
  • 92
  • 100
  • Thanks for your reply Machavity. So html caching and opcode caching are two different things. My code also does not change all the time but the data from mysql changes everytime. So I think I should look at some kind of output caching as you mentioned. – Jayesh Duggal Aug 11 '15 at 15:50