Does Opcache on PHP7 preallocate all assigned memory? - php

My opcache had a memory_consumption set of 512M and it was full.
So I increased it to 2048M, and restarted the php-fpm daemon. And it immediately filled up again:
This site is simply running a WP Multisite installation with 2 subdomain sites. Nothing special, really. It's a low traffic site, mostly static. It does have a Woocommerce shop, but with two products only. Nothing makes me think that this amount of cache consumption is justified.
Does PHP7's Opcache preallocate all of the memory it is configured to use?
Or is my cache genuinely filled?
Or am I setting the incorrect property?
My php-fpm config has:
php_value[opcache.memory_consumption] = 2048
How can I get further insight into what's going on?

The problem was in the way I had configured the opcache. I had configured it in the fpm pool by setting this property:
php_value[opcache.memory_consumption] = 2048
However, the right way of configuring it is in php.ini or in php.d:
opcache.memory_consumption=2048

Related

PHP-FPM slows down after a while - Opcache File Cache

My set up is a large drupal website with 50,000 requests per day. My main issue is that Php-fpm slows down after 10-15 minutes of a restart (1500+ code files). Cache is only full 40% (174mb of 512mb). Initial server response time is over 700ms but goes down to 170ms for first few minutes of a restart as per Google site speed testing.
I found this answer with similar issue and have added Opcache file cache with some improvement.
https://forums.cpanel.net/threads/php-fpm-restart-necessary-for-site-speed.650549/#post-2654105
Current Opcache Settings
[opcache]
opcache.enable=1
opcache.memory_consumption=512
opcache.interned_strings_buffer=64
opcache.max_accelerated_files=50000
opcache.max_wasted_percentage=15
opcache.validate_timestamps=0
opcache.revalidate_freq=0
opcache.mmap_base=0x20000000
opcache.file_cache='var/www/cache'
opcache.file_cache_fallback=1
Any other ideas on how to optimise the above to achieve consistent php-fpm performance. (Set up is Php-fpm 7.2, Nginx, Drupal, Mariadb on AWS server with 64G memory)
Tried adding File cache. It has shaved off 100ms but probably a lot more can be done.

Neither load front end nor back-end in Magento 2.2.3

I have installed Magento-2.2.3 in windows personal computer and after the installation it loaded first time well but after that it is not responding since an hour. Actually, I am new to Magento and anybody can tell about this problem?
Follow the below points this may help you.
enable all cache may help you. Full page cache .
MySQL 5.6 has some memory issues where a defaul config will use
about 500mb of ram, to fix set performance_schema = off in your
my.cnf and restart MySQL. Also make sure you have opcache turned on
and set to at least 64mb of ram and 10000 files cached, preferable
128mb. If you tune your config you can run on a 512mb vps but it's
tricky and you won't have enough ram for fpc on varnish and reddis
sessions. 1 gb vps with the above MySQL fix should work like a champ
out of the box on a vps.
There are lots of potential reasons why, but the most common is
around file system performance. In non-production mode especially,
we hit the disk pretty hard (lots of different files). E.g. in
developer mode we generate files on the fly (CSS etc). But without
more details (PHP version? using Vagrant? VM? Docker? OS? Memory? is
machine thrashing? etc), it is pretty hard to suggest something. Its
certainly not taking any where near that long on my laptop. Can you
provide any information about your setup? (But my first
investigation would be around I/O performance - for example using
Docker/VirtualBox with file syncing back to Windows is a dog -
because the file syncing is very slow.)

opcache has zero hits with cgi/fastcgi

I'm trying to get opcache working on my server that is hosting a website in apache2. I'm running debian 8.
However it seems to be hitting zero of the scripts.
I've already tried to change the php mode to cgi only but this didn't change anything. I've also tried to disable suPHP with the following command
a2endismod suPHP
again this didn't do anything for the problem.
Does anyone happen to know what could be causing this?
This was already answered here
To quote:
This looks like you are using cgi (FastCGI) rather than mod_php5. The shared memory area (SMA) is used for both, but it only persists request-to-request for the latter.
However, I should add that enabling following:
opcache.file_cache=/var/tmp/php/opcache
opcache.file_cache_only=1
made OPcache work with my setup - which is Apache+php as CGI/FastCGI (NOT php-fpm). Obviously this caching mechanism is filebased, not SHM (make sure
/var/tmp/php/opcache is accessible by webserver, might need 777 permissions).
You won't be seeing any cache hits/misses in the statistics after enabling the above, since - again - we disabled SHM Cache.
PS. sorry for necroposting, was just looking for a solution for a similar issue.

Opcache clears too quickly

I have setup my website on a new hosting (virtual cloud), however I am looking at the opcache and the scripts not being used for say a minutes or so are removed from the cache.
So is there a way to stop it? or is it a normal behaviour?
Thanks a lot.
There is configuration for that actually.
opcache.revalidate_freq=2, the default value is 2 seconds, opcache will try to check for timestamps every 2 seconds and if the files are changed it will revalidate.
You can change the value to match your needs, or you can just turn timestamp check off using this conf opcache.validate_timestamps=0, but in this case each time you deploy code to production you have to restart php-fpm (if you are using php-fpm) and web server
opcache.revalidate_freq=2 or any integer value
opcache.validate_timestamps=1 or opcache.validate_timestamps=0
Sounds like you need to define validate_timestamps=0 in php.ini. Beware of this though - if you upload any changes to your PHP files you will need to restart either Apache (if you use mod_php5) or PHP5-FPM, or clear the opcache manually.
For details on how to clear the opcache manually you basically have to create a PHP file with opcache_reset() and run it, but this has to be in the same SAPI as your other files - i.e. run by PHP5-FPM if that is what is serving the rest of your files.
http://ihaveabackup.net/2013/10/19/invalidating-the-opcache-in-php-5-5/

Windows 7 php + Symfony2 terribly slow

This is an issue I've been having for a long time. I want to run PHP applications on my windows computer and it has a terribly high load time, around 10-25 seconds. I have tried many things:
First I tried a simple XAMPP installation
I read WAMP might be faster, so I tried WAMP, too. It gave me the same results
Then I installed an nginx server with PHP, but it did not help either
Finally, I installed an Ubuntu 11.10 in VirtualBox and I shared my windows files containing my project, but the result was even worse: over 22 second load time each time.
UPDATE: I have even tried APC - it improved a bit but still 6-8 sec/page
I uploaded my files to a linux server(shared hosting), on which it runs in around 300-500 ms. On the XAMPP installation I tried to run other (i.e. not Symfony2) applications as well(e.g. phpmyadmin), which too were slower than on the shared hosting, but not extremely slow, with 2-3 sec load time. Until I change to Linux as the main OS, how could I improve performance? I have a laptop with i7 CPU, 4 GB RAM, 5400RPM HDD, Win7 x64.
Thank you for your help!
UPDATE2: For some mysterious reason my Symfony routing didn't work with fcgid (it gave me a 404 error for everything) so I went back for using PHP as a module. Now, it has become the worst ever (worse than it used to be as a module): app mode 20-25 sec, and in dev mode, over 30s every time, so I get a timeout error, and it's the same with or without APC enabled.
Here you can see this error. This is reproduceable: each time it reaches a different point of execution within 30s:
Update:
Since PHP 5.5 has now integrated the PHP OPCache, this speeds up the execution time. In my setup a full request with database access takes 180ms now.
Steps:
Update to the latest php version
Enable OPCache
Disable xdebug
Set realpath_cache_size = 2M as DemonTPx mentioned
php.ini settings:
realpath_cache_size = 2M
[XDebug]
xdebug.profiler_enable = 0
xdebug.remote_enable = 0
[opcache]
zend_extension = "C:\xampp18\php\ext\php_opcache.dll"
opcache.enable = 1
opcache.enable_cli = 0
opcache.memory_consumption = 128
opcache.interned_strings_buffer = 8
opcache.max_accelerated_files = 4000
Why is Windows slower than Unix?
As discussed here, PHP is very slow in file_exists, and filemtime() on Windows. since Symfony2 is using these functions in dev mode a lot. we won't get under 700ms (in <= 5.4) on Windows. PHP 5.5 allows now 180ms.
A solution could be WinCache which was developed by microsoft to solve this problem on IIS. But as it only works on several Windows versions and also only with IIS it's no solution for me.
Alternative
Also a nice solution I can recommend is to have a Linux Virtual Machine on Virtualbox. This is easy to setup and is also more like the production environment.
I have the exact same problem. Setting the following in php.ini increased the performance for me from ~800ms to ~300ms:
php.ini:
realpath_cache_size = 2M
Still not the ~100ms I get from a unix machine, but it makes a difference at least
I had a similar problem with symfony 1 for a time on XP and Server 2003. The solution was to install a PHP accelerator (eAccelerator for us, APC might be a better bet these days) plus FastCGI/fcgid.
Addendum: it's been ages since I've used Apache on Windows. I have generally been of the view that its performance has been getting steadily better, rather than worse; however as with most unusual set-ups, good results are not guaranteed. As per my earlier comment, I recommend asking your question at Apache Lounge, where I previously have received some great expert advice.
If memory serves correctly, they can offer you a free Apache binary compiled with better tools than the standard one offered on the Apache website.
Wow, After trying many different things, I've finally succeeded to move from a 15s execution time to a 3s exec time on windows7 with wamp.
How to install wincache extension :
http://us2.php.net/manual/en/wincache.installation.php
Where to download the wincache dll:
http://sourceforge.net/projects/wincache/
My php.ini config change:
[PHP]
realpath_cache_size = 2M
extension=php_wincache.dll
; XDEBUG Extension
;zend_extension = "C:/Net Generation/wamp/bin/php/php5.5.12/zend_ext/php_xdebug-2.2.5-5.5-vc11.dll"
;
[xdebug]
xdebug.remote_enable = off
xdebug.profiler_enable = Off
xdebug.profiler_enable_trigger = off
xdebug.profiler_output_name = cachegrind.out.%t.%p
xdebug.profiler_output_dir = "C:/Net Generation/wamp/tmp"
xdebug.show_local_vars=0
xdebug.max_nesting_level=200
[opcache]
zend_extension = "C:/Net Generation/wamp/bin/php/php5.5.12/ext/php_opcache.dll"
opcache.enable = 1
opcache.enable_cli = 0
opcache.memory_consumption = 128
opcache.interned_strings_buffer = 8
opcache.max_accelerated_files = 4000
i think you have a problem with caching mechanism.
check app\cache directory.
there has to be a folder named dev.
if it does not exist or if it is empty check folder permissions.
when i delete dev and prod directories under app\cache directory it takes 18 seconds to load the page but after that it takes only 500 ms.
Some years ago i had the same problem. Which antivirus software do you run in the background?
Try to deactivate it for dev purposes or change it. It also could be some indexing services running in the background. Symfony 2 consists of >15000 files with vendors :)
Also try to do it the classic way by reinstalling Windows from the scratch.
My sites takes usually from 100-500ms and my laptop is slower than yours. (Intel C2D P8600)
Just a guess (and probably not the right one), but it could be MySQL related. Seeing how you mentioned PhpMyAdmin and Symfony 2 as PHP applications you tested, both rely on MySQL (assuming you have MySQL set up in Symfony 2). You did not mention this in your post, but in your VirtualBox setup, did you by any chance let the script running on Ubuntu connect to the MySQL server on your Windows host machine?
You could check out PHP Benchmark for some performance testing scripts, and see if these scripts perform better timewise.
Another thing you could try is use Xdebug and see if you find (a) certain (group of) function(s) that are taking up too much time.
I'm definately gonna keep this question as a favorite, because I am too curious to see what it was now :) good luck !
Check your computer random access memory, RAM using http://oca.microsoft.com/en/windiag.asp or run the memory test application shipped with your Ubuntu CD booting option.
In both cases choose what know as extra or deep test - I don't remember exactly- How ever, choose the test with more longtime these kind of tests has no end, you just wait till the test finish two phases and any problems with your RAM, commonly, shown.
Also, Check your hard drive with any mean of checking. after that try to perform disk defragmentation
I bit, your problem is hardware related problem.
My pages were taking 20 seconds to execute. I installed fast cgi, increased memory limits, everything, not working. Then started looking at timeline and noticed symfony firewall module was taking up most of it time. Turns out having "localhost" in my config for doctrine is what was causing issues. Changing it to 127.0.0.1 fixed the problem. Not sure why, but it's described here:
http://12wiki.blogspot.ca/2012/11/why-does-symfony-2-firewall-take-so.html
Page loading time is depends on the CSS + JS + Image loading time also. I had the same problem in CakePHP and solved the problem by using mod_expires in htaccess.
Have you tried "ExpiresByType" in your server htaccess file for CSS, JS and images? Check this page.

Categories