php-fpm.conf for server hostname

Thank you for sharing! With "keys", is it the setting opcache.max_accelerated_files that you refer to?
 
Thanks. I have discovered a new problem now. Every time php-fpm restart or reload, then all my opcache is purged. Does anyone know how to avoid that? It is a problem, because I am going to have a big opcache and every time a customer add a domain or install a lets encrypt certificate, then opcache will be purged. That means it will be purged several times every day.
 
A reply to my self: Regarding opcache is reset during php-fpm restart/reload. I will test "out opcache.file_cache" wich enables and sets the second level cache, hopefully it will improve perfomance when opcache is reset in RAM.
 
That's it's normal behavior and it cannot be different - the opcache is in RAM of the main process and killing the main process will kill the cache as well. That's another reason to not use cache larger than 256MB :)

The secondary cache (the file cache) is OK if you are going to target saving CPU time. AFAIK it does not help much with disk operations which is the usual bottleneck. If I am right and your CPU is not loaded to the max, you won't benefit from file_cache, so better keep it off.

The beauty of opcache is that you can start/reconfigure/reload without making impact on the server other than temporary higher loads. So tests in the nighttime when the server is not loaded much are OK.
 
It does help a lot, the result was that there was no impact of performance after reset of opcache. I used these settings:

Code:
opcache.file_cache=/.opcache
opcache.file_cache_only=0

Please don't misunderstand the opcache.file_cache, opcache in memory will continue as before and will be used, but if you for example restart php-fpm, then opcache in memory is reset, and the first page load will then use the file_cache, then the next will use cache from memory.

I do not agree with about the low opcache size. I see no point in providing only a handful of sites opcache on servers with millions of php files. Of course I want big opcache, to get the best performance for as many as possible.

Now with the opcache.file_cache as fallback (second level cache), the cached scripts is having the same speedy respons both on first and second page load after opcache in memory is reset.

Edit: To make sure nobody misunderstand, let me add that the cache in opcache.file_cache will not be reset after restart of php-fpm. I think it will even survive a server reboot (not tested).
 
Last edited:
It constantly copies the memory to cache, which are disk operations. My bottleneck is the disk (it's SSD but it's loaded a lot) so I prefer leaving it off.

And I have 99.98% hit rate with 256MB cache. The PHP files on the server are not as much as yours, but ~380 000.

opcache_hit_rate 99.98%
 
Last edited:
Here's an idea to consider - leaving the secondary cache on another drive which is not used for the user files (like I have one for the admin backups partition). I will give that a try.
 
It constantly copies the memory to cache, which are disk operations. My bottleneck is the disk (it's SSD but it's loaded a lot) so I prefer leaving it off.

That is not correct if you test this out. If the file does not exist in opcache.file_cache, it will be created. If the file exist in opcache.file_cache but has a new timestamp, it will be updated. If the file in opcache.file_cache exist but have not changed, nothing will happen with the file.
 
Unfortunately I have a new problem with opcache.file_cache wich I am not able so solve yet. You can read about the trouble in my latest replies here: http://forum.directadmin.com/showthread.php?t=52511

But then I solved it, but I was wrong. Previos I was only able to get opcache.file_cache to work for user webapps, then I though I solved it by using this path:

opcache.file_cache=/.opcache

Then the one regular user did get cached files in that directory. But when I test more, it is now only that regular user. Not webapps or any other users get files cached at /.opcache - only one of the users.

I don't get it.
 
More information about opcache.file_cache. When I delete the file cache in /.opcache and then restart php-fpm, the file cache will be generated in ./opcache for the first user that get visit on his site. After that, only this user will get written cache to /.opcache.

So, opcache.file_cache only work for one user, and it is the first user that get trafic. Please share if you know how to fix this.
 
Thank you for confirmation. I think the problem would be solved if I was able to change this opcache.ini value to be dynamic:

opcache.file_cache=/|HOME|/.opcache

Where "|HOME|" would automatically instert "home/USERNAME" so that every user would have their own path in php.ini to /home/USER/.opcache - then we would also need a script to create the directory /.opcache automatically on user creation in DirectAdmin.

But first thing is to get the dynamic path to be insterted in php.ini with custom path to opcache.file_cache= in every own user /home/USER/.opcache

I don't know how. Please share if you do.
 
If you enable custom php.ini per user, then you can have custom setting added in the user php.ini. I am unsure however how you can automate the setting to be added in it :)

By the way it actually makes some sense. It's true that the opcache is in the master php-fpm process; however the compilation of the scripts is done in the childs, so it's the childs who are making addition to the cache.
 
Or maybe it is possible to edit /usr/local/directadmin/data/templates/custom/php-fpm.conf and add this:

php_admin_value[opcache.file_cache] = |HOME|/.opcache

I have no idea if it will work. My head is burning. Will try to test soon.
 
I just tested it with .htaccess:

Code:
php_flag opcache.file_cache ...

Sorry, no effect at all.
 
php_flag in users .htaccess when using php-fpm will not work and will cause internal server error. php-fpm users can't use .htaccess to change php settings.
 
That is UNTRUE.

Here is a live example for you:

Code:
root@srv2:/home/cphpvb/public_html/test # touch test.php
root@srv2:/home/cphpvb/public_html/test # chown cphpvb:cphpvb test.php
root@srv2:/home/cphpvb/public_html/test # echo "<?php not_existing_function(); ?>" > test.php
root@srv2:/home/cphpvb/public_html/test # touch .htaccess
root@srv2:/home/cphpvb/public_html/test # echo "php_flag display_errors on" > .htaccess

Result is:

1.png

then

Code:
rm .htaccess

// display_errors is disabled by default

the result is:

2.png

And yes, I do use PHP-FPM 7.1 on that hosting.

Code:
root@srv2:/home/cphpvb/public_html/test # grep "php" /usr/local/directadmin/custombuild/options.conf
php1_release=7.1
php1_mode=php-fpm
php2_release=5.4
php2_mode=php-fpm
php_ini=yes
php_timezone=Europe/Sofia
php_ini_type=production
 
Last edited:
It is true for me. I get internal server errors if I change php settings in .htaccess in user public_html. Also it states the same in the guide: https://help.directadmin.com/item.php?id=682

in cases like php-fpm, where .htaccess files are not available for php settings.

I only have ONE php version using php-fpm. If it works for you, maybe it is related to having several php versions and some that is not using php-fpm? I don't know.
 
I am unsure if it can change the opcache behaviour though... I am sure it does not throw an error when I set it. But is it working? :)
 
Back
Top