Forum Moderators: coopster

Message Too Old, No Replies

Are handlers irrelevant after using PHP-FPM

         

csdude55

8:52 pm on Nov 22, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm kind of confused about this... if I turn on FPM for all of my sites, does that make PHP Handlers completely irrelevant?

I have a few sites using PHP 5.6, and the others all use PHP 7.4. The handler for 5.6 is set to DSO, which I understand isn't supported by HTTP/2. As I was about to install FastCGI and try to compare it with CGI and suPHP, I read the very vague PHP Handlers do not apply to PHP-FPM. Does that mean that I can completely ignore the handlers now, and skip installing FastCGI?

robzilla

10:31 pm on Nov 22, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



PHP-FPM is a PHP handler of sorts, i.e. it handles PHP execution. The big difference is that it's not a module built into Apache but a program that runs completely separately from Apache. You use a module to proxy [httpd.apache.org] all PHP requests to the port or socket that it's listening on.

Weird that support for HTTP/2 is reliant on the PHP handler, but I haven't used Apache in a long long time.

csdude55

8:05 am on Nov 23, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Well, I switched my site to PHP-FPM and it was MUCH slower! Everything in Munin looked normal (no real impact from before I changed it), but my load time skyrocketed! So I had to switch it back.

I guess my next step is to install mod_fcgid, then change my Handler to FastCGI? The whole thing is very confusing, and I'm really just throwing darts at a board to see what sticks.

FWIW, here's where I read that HTTP/2 isn't compatible with DSO:

[docs.cpanel.net...]

robzilla

12:55 pm on Nov 23, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



PHP-FPM requires more configuration than other handlers, but is potentially faster than the other handlers. I don't know what defaults are set here but if, for example, opcode caching is not automatically enabled, performance will suffer.

JorgeV

3:16 pm on Nov 23, 2020 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member Top Contributors Of The Month



Hello,

I stopped using Apache sine at least 10 years, so I can't help about it. But you shouldn't see noticeable performances difference between mod_php and PHP-FPM implementation. mod_php is slightly faster, because it's embedded into Apache, but for everyday situation, this should end to b the same.

csdude55

8:11 pm on Nov 23, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The defaults for PHP-FPM that I can change in WHM are:

PHP-FPM Pool Options
Max Requests: 20
Process Idle Timeout: 10
Max Children: 5

PHP INI Directives
Treat URLs as files (allow_url_fopen)
Log errors (log_errors)
Recognize code between <? and ?> tags as PHP source (short_open_tag)

I don't know if the "Pool options" (whatever that means) are default for everyone, or if they're based on my global Apache configuration. I don't see anything in WHM about opcode caching, and I usually don't customize anything manually because WHM has a tendency to overwrite those files when it updates :-(

I wish that I could embed an image here to show you what happened when I used FPM... none of my stats seemed to change, Apache processes and volume stayed essentially the same, but my HTTP loadtime skyrocketed! Previously in the week my maximum load time was 0.4, but yesterday (with FPM) it hit 9.76! Users complained that the site was timing out a lot, but I didn't see that myself.

I really don't have any issues with using the DSO handler (which is mod_php, right?), but I have to change it to something else for HTTP/2 so I'm experimenting. Everything I've read implies that DSO is the fastest, with FastCGI being the second fastest but requiring more memory. So I guess I really need to figure out whether the more memory required by FastCGI offsets any savings from HTTP/2?

csdude55

7:06 am on Nov 24, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm deviating a little from the subject, but this is still on the Handler...

I installed mod_fcgid (FastCGI) and activated it for PHP 5.6. But that caused a major problem: I clicked on a page and it tried to download it instead of open it, and then PHP code started being displayed on the screen! Changing it back to DSO fixed it back to normal.

That almost gave me a heart attack, it was downloading raw source code! Luckily it was at 2am and only for a minute, so hopefully nobody noticed :-O

robzilla

8:40 am on Nov 24, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The PHP-FPM master process starts up a number of worker processes that handle the actual PHP processing. Together, those form a pool. The bigger the pool, the more requests you can handle simultaneously. Those defaults don't look great for a busy site, but they shouldn't necessarily cause long load times either.

If you have a phpinfo() page somewhere, that can tell you if an opcode caching module is included and enabled.

HTTP/2 seems to have stopped working on my older CentOS 6 boxes due to Chrome switching from NPN to ALPN, which requires OpenSSL 1.0.2 or newer. Maybe that's something that cPanel or EasyApache takes care of for you, but I'd have to build nginx from source with a version of OpenSSL that CentOS 6 doesn't natively support. I'll be upgrading to CentOS 8 soon anyway, so that I can also take advantage of TLS 1.3 and any upcoming performance enhancements. One week until EOL for CentOS 6, I should hurry up :-)

As for switching between PHP handlers, as you've seen there can be uncomfortable side effects, so I would limit these experiments to a test site or, ideally, a test server.

csdude55

7:20 pm on Nov 24, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I just ordered a new VPS, so I'll be transitioning to CentOS 7 this week. I was hoping to get everything ready for a simple crossover, but I guess I'll have to play more when I'm actually on the new server. Oh well.

I'll be leaving my old server online through December to make sure the DNS has propagated everywhere, so I guess I could use it for a test server. I was hoping it would be easier than that, especially since I have no idea if this will have any actual impact on anything... but it's there, so why not?

robzilla

8:40 pm on Nov 24, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Can't you get CentOS 8? EOL for 7 is "only" 3,5 years away. Newer tends to be better in this case.

csdude55

2:02 am on Nov 25, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Good point, so I asked... they said that cPanel is still experimental on CentOS 8 and has no support at this time :-( Since cPanel is something I've always promoted with my hosting plans, I have to have it. So I guess I'll have to stick with 7 for now.

robzilla

12:32 pm on Nov 25, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'd wait it out, it looks like it's on the roadmap for this year [twitter.com].

JorgeV

1:06 pm on Nov 25, 2020 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member Top Contributors Of The Month



Also, keep in mind that Cpanel is increasing its prices on January 1st .. . I never used Cpanel, so I don't know how much tthis increase is compared to actual prices.

csdude55

8:27 pm on Nov 25, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The company I'm using for my VPS is great to work with, they already promised that they'll help me transition to CentOS 8 when it's supported at no charge. So that makes me pretty happy :-)

@JorgeV, you're right that their prices are going up. I don't know their old price because it was "technically" included with my old VPS, but I've learned that it was about 50% of what I was paying. But I've always promoted my hosting packages as including cPanel, so it's too late to just drop it now :-( I wish I'd realized that a few years ago, I would have promoted VirtualMin instead and saved some money!

csdude55

8:41 pm on Nov 25, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Back to PHP-FPM, though... the default settings are:

Max Requests: 20
Process Idle Timeout: 10
Max Children: 5


I'm not sure if this is relevant, but my Apache settings are:

Start Servers: 15
Minimum Spare Servers: 10
Maximum Spare Servers: 20
Server Limit: 256 (default)
Max Request Workers: 150 (default)
Max Connections Per Child: 10000 (default)
Keep-Alive: On
Keep-Alive Timeout: 5 (default)
Max Keep-Alive Requests: 100 (default)
Timeout: 60


Can you suggest how I might modify FPM's configuration to improve the load time? I'm thinking to change it to:

Max Requests: 20 (matching Max Spare Servers)
Process Idle Timeout: 60 (matching Timeout)
Max Children: 10000 (matching Max Connections Per Child)

robzilla

10:20 pm on Nov 25, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Max Requests: 20 (matching Max Spare Servers)
Max Children: 10000 (matching Max Connections Per Child)

Might one to swap these values ;-)

What I like to do is estimate how many workers (children) I'll need to have handling requests simultaneously, then monitor how frequently extra workers are needed throughout the day and adjust accordingly. Since you're already using Munin, have a look at the PHP-FPM plug-ins.

Other settings ought to include start_servers, min_spare_servers and max_spare_servers.