php-fpm.conf for server hostname

P.S. The solution to my problem of course is migrating from SuPHP to PHP-FPM and start using some caching there... I know it, but I am lazy to do it :)
 
I did migrate from SuPHP to PHP-FPM and the disk usage reduced significantly which caused the load to drop in half.

I am currently unsure why, but the ondemand config

pm = ondemand
pm.max_children = 70
pm.process_idle_timeout = 60
pm.max_requests = 1000

works slightly better than the dynamic one

pm = dynamic
pm.max_children = 70
pm.start_servers = 20
pm.min_spare_servers = 20
pm.max_spare_servers = 50
pm.max_requests = 1000

It's not a big difference but still it's surprising for me that ondemand causes lower load than dynamic...

Both configs were tested with the following opcache settings:

opcache.memory_consumption=256
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10099
opcache.revalidate_freq=60
opcache.validate_timestamps=1
opcache.fast_shutdown=1
opcache.enable_cli=1
opcache.validate_permission=1

I guess revalidate_freq=60 is a bit of a small security risk... but I guess it's worth it.
 
Last edited:
Hm. I am not sure why ondemand give lower load, probably related to that it does not need to keep for example 20 servers always for each domain, even though the domains is not getting trafic.

I have almost decided to go for dynamic on my shared hosting servers, because I want the extra performance. I might put in more RAM in my servers, just because I want dynamic. :) Currently I am considering this value for my setup:

Code:
pm = dynamic
pm.max_children = 400
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.max_requests = 0

I might set a value on pm.max_requests just to be safe, I have not decided yet.
 
Last edited:
However I am not going to use opcache, because my customers would be confused if they edit their php code and do not see the changes immediately.
 
opcache with the following settings will give no confusion at all:

opcache.revalidate_freq=0
opcache.validate_timestamps=1

It gives a little disk usage but it is much lower than reading the file, especially if you are using HDD.
 
Thank you. So I might have misunderstood the possibility. With those settings, if a user make changes to the php code in one of his websites, the change will be visible already on first page load?

Something else about opcache, I found a very interesting article I want to share: https://ma.ttias.be/mitigating-phps-long-standing-issue-opcache-leaking-sensitive-data/ - however I see you aready have opcache.validate_permission=1 in your settings. Do you think it also is needed with opcache.validate_root=1 on shared hosting servers?
 
LOL, what a good catch this is.

Code:
opcache.validate_root=1

is a must since:

Prevents name collisions in chroot'ed environments. This should be enabled in all chroot'ed environments to prevent access to files outside the chroot.
 
Thank you for the confirmation. I will for sure test opcache tomorrow.
 
I guess the DirectAdmin staff should DISABLE opcache (opcache.enable=0) by default for any PHP versions lower than 5.6.30 because they are vulnerable AND add the opcache.validate_root=1 as default too.
 
Another important thing - opcache.cwd must be 1 on shared hosting (happily it is 1 by default) and, if using symlinks, opcache.revalidate_path must be 1 too (it's 0 by default).

Here is my current setup which I guess is safe enough (with exception of the opcache.revalidate_freq but it's a speed tradeoff that way):

Code:
opcache.memory_consumption=256
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10099
opcache.revalidate_freq=60
opcache.validate_timestamps=1
opcache.fast_shutdown=1
opcache.enable_cli=1
opcache.validate_permission=1
opcache.validate_root=1
opcache.use_cwd=1
opcache.revalidate_path=1
opcache.enable_file_override=1
 
Last edited:
I have tested opcache, and it greatly improve the performance. Now I only need to figure out how much memory and files I should give on:

Code:
opcache.memory_consumption
opcache.max_accelerated_files

Because I don't think opcache does much good if there is not enough memory for all sites. There is like 400+ WordPress sites on one of the servers, and also some others like Drupal. I wonder how much memory and files I should consider for opcache for each WordPress site? Approximately?
 
I guess I can deactivate opcache.enable_cli when I am using PHP-FPM, because it is using fastcgi and not cli?

CLI is when you run php scripts from the console (SSH).

I have tested opcache, and it greatly improve the performance. Now I only need to figure out how much memory and files I should give on:

Code:
Because I don't think opcache does much good if there is not enough memory for all sites. There is like 400+ WordPress sites on one of the servers, and also some others like Drupal. I wonder how much memory and files I should consider for opcache for each WordPress site? Approximately?[/QUOTE]

Of course it depends but usually nothing more than 256MB will provide improvement. The problem is that the larger the cache is - the slower it is supported. So at one point you start wasting ram memory and cpu time for caching something, which is not used.

When the memory is full, opcache frees it by removing the oldest scripts in the cache. If one file is hit very frequently, it "restarts" as the newest in the cache. So files which are frequently accessed (the files on the busy sites) will remain in the cache while less frequently accessed files will eventually drop from it.

Basically the deal is like that - do you need to keep a file which is accessed two-three times per hour persistently in the cache? Definitely it does not benefit anything - it is actually bad, because it just wastes ram and (a little) cpu time. So better let it drop out from it.
 
[..]Of course it depends but usually nothing more than 256MB will provide improvement. The problem is that the larger the cache is - the slower it is supported. So at one point you start wasting ram memory and cpu time for caching something, which is not used.[..].

I have not found anything in the documentation and not anything while searching a lot, that say opcache will be slower if opcache.memory_consumption and opcache.max_accelerated_files is set very high.

I want to set it very high, because it is a big server with many domains. One of the servers has more then 1,3 million .php files.

I am considering setting opcache.memory_consumption to about 16 GB. Unless I can find documentation that says this will make opcache slower.
 
Benchmark it. Run for one day with large cache, then run for one day with 256. Compare your average load and share :) If all your sites are pretty well loaded, then I would agree for a benefit. My experience in shared hosting is different. Usually most of the sites are very low traffic and I see no benefit in caching them.
 
Last edited:
This is production servers. So I will avoid changing settings so dramatically for a day. I have not found any places saying large opcache will make it slower. So I will go for the high setting. I see no point in only cache scripts from a handfull of domains on servers with so many domains.
 
Restart and reconfigure of opcache is having no effect on the end users. It's no problem for testing with this on the production server. And I bet you'll see no speed difference. Save your GB of ram and better give them to MySQL :)
 
Well I have already tested with scripts in opcache, and without, of course there is big difference in speed.

Of course it matters that it is production. I do not want a whole day with only 256 mb opcache.

Edit: Also restart and reconfigure of opcache, will result in all cache to be wiped. Do not want that more often then needed.
 
I've been following this thread with interest and want to share some observations I had with opcache.

- some statistics programs that use .php or .inc files to store data do not work correctly with opcache. Use a blacklist to prevent this. Set opcache.blacklist_filename=/xyz/opcache_blacklist.txt in php.ini
- keys seem to consume a lot of memory so don't forget to reserve a fair amount for this. Perhaps even more important than the memory for cached php scripts.

My useful script suggestion: https://gist.github.com/ck-on/4959032/?ocp.php
 
Back
Top