{"id":2123,"date":"2022-08-30T15:22:14","date_gmt":"2022-08-30T15:22:14","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/01\/02\/how-to-configure-mysql-php-to-use-less-memory-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:22:14","modified_gmt":"2022-08-30T15:22:14","slug":"how-to-configure-mysql-php-to-use-less-memory-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/how-to-configure-mysql-php-to-use-less-memory-collection-of-common-programming-errors\/","title":{"rendered":"How to configure MySQL\/PHP to use less memory?-Collection of common programming errors"},"content":{"rendered":"<p>What you should do, is retain Linux, Mysql and PHP, but do away with Apache. Or at least, stop running PHP in-process with Apache.<\/p>\n<p>The chances are you&#8217;re using the Apache prefork model with an in-process PHP module. This is very bad for memory efficiency on most workloads, because it keeps a heavy PHP process open even for HTTP connections which aren&#8217;t requesting any dynamic content just now.<\/p>\n<p>What you want to do instead is use another web server (for example Nginx, but Apache would work too) and run PHP as a FastCGI daemon. This is easy to set up and googling for &#8220;PHP fastcgi&#8221; returns numerous examples.<\/p>\n<p>You can then have a small, fixed number of &#8220;heavy&#8221; processes running PHP (No more than a couple per core, I reckon), but still have good capacity for running real applications, because &#8220;idle&#8221; HTTP connections, such as those serving keep-alives or waiting for requests don&#8217;t use up the &#8220;heavy&#8221; processes, only the lighter web server processes.<\/p>\n<p>A web server which uses limited forking \/ few processes is probably better &#8211; such as Nginx, or Apache with a different thread model. This is incompatible with mod_php, which is why you need to run it as FastCGI instead.<\/p>\n<p id=\"rop\"><small>Originally posted 2014-01-02 12:07:10. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>What you should do, is retain Linux, Mysql and PHP, but do away with Apache. Or at least, stop running PHP in-process with Apache. The chances are you&#8217;re using the Apache prefork model with an in-process PHP module. This is very bad for memory efficiency on most workloads, because it keeps a heavy PHP process [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2123","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2123","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2123"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2123\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2123"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2123"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2123"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}