logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Apache Memory Issues PHP as module (solved with mod_fcgid)
Author
tdellinger



Joined: 19 Jul 2018
Posts: 8
Location: US, McKinney TX

PostPosted: Wed 26 Apr '23 14:10    Post subject: Apache Memory Issues PHP as module (solved with mod_fcgid) Reply with quote

I have encountered a problem similar to what Razzi29 wrote about on Feb 6. At 2 of our customer sites, Apache kept increasing in memory usage, often exceeding 6 GB. Normally, our Apache servers use around 300 MB. I noticed that at the problem sites the amount just keeps increasing.

We are running Apache and PHP. I tried changing PHP versions thinking that would be the issue, but it didn't make a difference. So started testing with different versions of Apache and found that it appears to have started with Windows Apache version 2.4.55. 2.4.54 VS 16 and VS 17 seem to run OK.

Any thoughts?

Thanks!

Tom
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Wed 03 May '23 9:54    Post subject: Reply with quote

Hi Tom,
do you run PHP as a module loaded in apache or over fcgid?
Back to top
tdellinger



Joined: 19 Jul 2018
Posts: 8
Location: US, McKinney TX

PostPosted: Wed 03 May '23 14:06    Post subject: Reply with quote

Hi James,

Thanks for the response, I am running PHP as an apache module. Should it be run using fcgid?
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Wed 03 May '23 18:51    Post subject: Reply with quote

On Windows PHP often tends to have memory leaks with extensions. There is a tutorial(1) how to change your setup to fcgid. You can run PHP as a module and over fcgid at the same time in different vhosts.

Also recommend to check try adding the following block at the end of httpd.conf


Code:
 
EnableMMAP Off
EnableSendfile Off

AcceptFilter http none
AcceptFilter https none
 



(1) https://www.apachelounge.com/viewtopic.php?t=2394[]
Back to top
tdellinger



Joined: 19 Jul 2018
Posts: 8
Location: US, McKinney TX

PostPosted: Wed 03 May '23 22:55    Post subject: Reply with quote

Thank you for the info, will try running php with fcgid.

Tom
Back to top
dpat99



Joined: 15 May 2023
Posts: 5

PostPosted: Tue 16 May '23 10:29    Post subject: Same problem Reply with quote

Hi guys,

We have the same problem it seems.

Did running with fcgid solve your problem?

/ Patrik
Back to top
tdellinger



Joined: 19 Jul 2018
Posts: 8
Location: US, McKinney TX

PostPosted: Tue 16 May '23 15:15    Post subject: Reply with quote

We have not yet installed the change to fcgid on a customers site (where the problem was occurring) since we wanted to ensure the functionality and performance would be OK using fcgid and it appears to be working ok at the moment with the older Apache.

We already have an fcgid program (mapserver) so want to make sure that both php and mapserver have the correct fcgid configurations.
Back to top
dpat99



Joined: 15 May 2023
Posts: 5

PostPosted: Tue 16 May '23 21:48    Post subject: Reply with quote

Thanks for the update!
Back to top
BrainFooLong



Joined: 31 May 2023
Posts: 5

PostPosted: Wed 31 May '23 10:32    Post subject: Reply with quote

We had exactly the same problem here. Apache memory usage increased slighty from day to day. Finally ended up in crashing the server at midnight, by eating up all free memory.

We run PHP 8.2 here on windows server machines.

I cannot say if ever increasing memory was a thing before 2.4.54, as we not have properly monitored RAM usage the time we had 2.4.54 and older versions. But i definetely had a crash the first time because of no free RAM with apache.

Monitoring tells, it climbs very slighty, depending on the server request load (We have multiple servers, from 200k daily requests down to 20k daily requests).

A apache restart frees all blocked memory. In the task manager it is clearly visible that apache blocks the memory.

We finally decided to not wait for a fix and switched to FCGI (With mod_fcgid). Daily server/apache restart is a No-No for us, but would maybe workaround the issue. We now have this running a few weeks and everything looks good with FCGI and PHP on windows. Once you have figured out the correct apache config for the FCGI parts, it run smoothly.

I cannot spot any performance impact/difference. Request/Response times are equal. No hickups, no new errors in error logs. RAM stays equal, with spikes depending on current requests (Which is expected). But it returns to normal after the requests are done.


So, TLDR: mod_fcgid works for us and resolves the issues with memory consumption.

Here is our config for the onces who are interested (We have some really long running PHP jobs, if you wonder about large timeouts):

Code:
LoadModule fcgid_module modules/fcgid/mod_fcgid.so

# 2GB file upload equals to php.ini max_upload_size
FcgidMaxRequestLen 2147483648

# increase fcgid timeout to 5 hours
FcgidIOTimeout 18001
FcgidBusyTimeout 18001
FcgidIdleTimeout 18001

FcgidInitialEnv PHPRC "/www"

<FilesMatch \.php$>
   Options +ExecCGI
   SetHandler fcgid-script
   FcgidWrapper "/srv/php8/php-cgi.exe" .php
</FilesMatch>
Back to top
tdellinger



Joined: 19 Jul 2018
Posts: 8
Location: US, McKinney TX

PostPosted: Wed 31 May '23 14:49    Post subject: Reply with quote

Thanks for the info. We have not been able to recreate the problem on a local system, but we have a couple of customers that are experiencing this. I am trying to get some time on their systems so we can switch them over to FCGI and do some basic tests.

We did do some performance tests on a local system using FCGI and the results appear to be comparable.

Thank you for your configuration information. I used the same FCGI parameters as described in https://www.apachelounge.com/viewtopic.php?t=2394 and it worked well.
Back to top
Jan-E



Joined: 09 Mar 2012
Posts: 1265
Location: Amsterdam, NL, EU

PostPosted: Tue 06 Jun '23 17:32    Post subject: Reply with quote

Quote:
We had exactly the same problem here. Apache memory usage increased slighty from day to day. Finally ended up in crashing the server at midnight, by eating up all free memory.

My Apache 2.4.56 (own built) has been running with PHP 8.1.18 as mod_php since May 14th. I have been monitoring the mem usage during the last week. Sometimes the memory goes up to 2.5GB, but when being quite idle for some hours it also goes down again. Last Saturday the memory usage went down to 181.2MB. That is probably as low as it can get, because OPcache alone takes almost 158.4MB by now. So I really do not have the problem of ever increasing memory usage.

What memory usage are we talking about in your cases?
Back to top
tdellinger



Joined: 19 Jul 2018
Posts: 8
Location: US, McKinney TX

PostPosted: Tue 06 Jun '23 18:48    Post subject: Reply with quote

We are running PHP 7.4.x (such as 7.4.33). At one customer site that was having memory issues, Apache reached around 8.6 GB. At that point, 98% of the system memory was being used out of a total of 12GB, so we stopped Apache. For us, normally Apache only uses 200 to 300 MB.

At another customer site with the same problem, I was able to change to use PHP fcgid and Apache is staying around the 200 to 300 MB range and everything is looking good.

Tom
Back to top
BrainFooLong



Joined: 31 May 2023
Posts: 5

PostPosted: Mon 19 Jun '23 8:50    Post subject: Reply with quote

Jan-E wrote:
What memory usage are we talking about in your cases?


For us, we have a 1 month maintenance cycle with restarting apache each month once.

21 days after last restart, apache had about 7G~ used RAM and crashed (Because all OS memory was fully used).
It increased from 100MB at start to the 7G in about 21 days with round about 21 million requests done in that time.

We have times of almost full idle each night, so it should recover, but never had.

Fixed with FCGI usage as stated above.
Back to top
Jan-E



Joined: 09 Mar 2012
Posts: 1265
Location: Amsterdam, NL, EU

PostPosted: Tue 20 Jun '23 19:01    Post subject: Reply with quote

Strange. I happened to be looking at my server for a while now. Apache shrank from 1383 MB to 1105 MB in less than 2 hours.

Edit: yet another hour later Apache’s memory footprint is 1058 MB. It keeps on shrinking.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Mon 26 Jun '23 11:08    Post subject: Reply with quote

It helped me move the session handling from files to Redis.
Since Apache does not have to watch all the open session files from PHP.

Code:

session.save_handler = redis
session.save_path = "tcp://127.0.0.1:6379"


The Redis server: https://github.com/microsoftarchive/redis/releases

Does anyone know a newer version for Windows?
Back to top
Jan-E



Joined: 09 Mar 2012
Posts: 1265
Location: Amsterdam, NL, EU

PostPosted: Mon 26 Jun '23 11:32    Post subject: Reply with quote

James Blond wrote:
Does anyone know a newer version for Windows?

https://github.com/zkteco-home/redis-windows
Linked on https://stackoverflow.com/a/10525215/872051

On-topic: a Apache on my Windows server was restarted 8 days ago. I saw it once top at 3.1GB, but yesterday morning it was back at 190MB.
Back to top


Reply to topic   Topic: Apache Memory Issues PHP as module (solved with mod_fcgid) View previous topic :: View next topic
Post new topic   Forum Index -> Apache