{"id":8555,"date":"2020-04-30T14:28:27","date_gmt":"2020-04-30T18:28:27","guid":{"rendered":"http:\/\/local.brightwhiz\/?p=8555"},"modified":"2022-08-28T15:06:01","modified_gmt":"2022-08-28T19:06:01","slug":"increase-php-memory-limit","status":"publish","type":"post","link":"http:\/\/local.brightwhiz\/increase-php-memory-limit\/","title":{"rendered":"Three Ways to Increase the PHP Memory Limit"},"content":{"rendered":"\n

Here is how to increase the PHP memory limit and avoid crashing your web applications using anyone of the three convenient ways.<\/p>\n\n\n\n

Generally, PHP<\/a> scripts are only allowed to use a certain amount of memory per request. This is for good reason. It prevents rogue or badly written scripts from gobbling up all the available memory on a server and wreaking havoc on other services and applications running on the same server.<\/p>\n\n\n\n

There are times when a script may require more memory than that which has been allocated by the server admin. This is easy to detect as the webserver error logs should print out a line similar to this:<\/p>\n\n\n\n

PHP Fatal error: Allowed memory size of x bytes exhausted (tried to allocate x) in yourscript.php<\/code><\/pre>\n\n\n\n

Where x is the amount in bytes your PHP tried to allocate.<\/p>\n\n\n\n

To fix this issue you need to increase the PHP memory limit. There are three main ways to do it.<\/p>\n\n\n\n

  1. Via the PHP configuration file (php.ini)<\/li>
  2. Via the web server .htaccess file<\/li>
  3. At the Start of your PHP script via the ini_set() function<\/li><\/ol>\n\n\n\n

    Increase PHP Memory Limit via php.ini file<\/h2>\n\n\n\n

    This method will affect all scripts running in the affected system. You will need to open the file with your favorite text editor and find the line that looks similar to this:<\/p>\n\n\n\n

    memory_limit = 16M<\/code><\/pre>\n\n\n\n

    The location of the php.ini<\/code> file really depends on the Operating System<\/a> and in some cases the version number.<\/p>\n\n\n\n

    Check out this guide on PHP configuration files for details<\/a><\/strong><\/p>\n\n\n\n

    Increase the limit in Megabytes (M). The amount you set for the limit really depends on the applications you are running on the server.<\/p>\n\n\n\n

    You then need to restart the webserver for the changes to take effect.<\/p>\n\n\n\n

    Check out this guide on how to start, stop, and restart the Apache service<\/a><\/strong><\/p>\n\n\n\n

    Using the web Server .htaccess File<\/h2>\n\n\n\n

    This method allows you to increase the memory limit at folder scope. This can be achieved using the .htaccess<\/strong> file. You can add the following line to an existing .htaccess<\/strong> file or create one using a text editor.<\/p>\n\n\n\n

    php_value memory_limit 256MB<\/code><\/pre>\n\n\n\n

    The above directive will apply to the current folder and all child folders.<\/p>\n\n\n\n

    Using the the ini_set() function<\/h2>\n\n\n\n

    There are many cases where it may not be advisable to increase the PHP memory limit server-wide nor folder-wide. This method allows you to increase the memory limit just for the script that needs it.<\/p>\n\n\n\n

    All you need to do is add the following line to your PHP script preferably at the top.<\/p>\n\n\n\n

    ini_set('memory_limit', '256MB');<\/code><\/pre>\n\n\n\n

    That should be localized to the current script.<\/p>\n\n\n\n

    There you have it. Three ways with their use-cases show you how you should increase PHP memory limit and in what contexts.<\/p>\n","protected":false},"excerpt":{"rendered":"

    Here is how to increase the PHP memory limit and avoid crashing your web applications using anyone of the three convenient ways. Generally, PHP scripts are only allowed to use…<\/p>\n","protected":false},"author":1,"featured_media":8556,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,27,16],"tags":[58,320,433,449,452,526,531,635,636,638,643],"yoast_head":"\nIncrease the PHP Memory Limit Using Three Easy Ways<\/title>\n<meta name=\"description\" content=\"Here is how to increase the PHP memory limit and avoid crashing your web applications using anyone of the three convenient ways\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/local.brightwhiz\/increase-php-memory-limit\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Increase the PHP Memory Limit Using Three Easy Ways\" \/>\n<meta property=\"og:description\" content=\"Here is how to increase the PHP memory limit and avoid crashing your web applications using anyone of the three convenient ways\" \/>\n<meta property=\"og:url\" content=\"http:\/\/local.brightwhiz\/increase-php-memory-limit\/\" \/>\n<meta property=\"og:site_name\" content=\"Brightwhiz.com\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/brightwhiz\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-04-30T18:28:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-08-28T19:06:01+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2020\/04\/php-memory-limit.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Michael Bright\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@brightwhizmag\" \/>\n<meta name=\"twitter:site\" content=\"@brightwhizmag\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Michael Bright\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"http:\/\/local.brightwhiz\/increase-php-memory-limit\/#article\",\"isPartOf\":{\"@id\":\"http:\/\/local.brightwhiz\/increase-php-memory-limit\/\"},\"author\":{\"name\":\"Michael Bright\",\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/person\/81f0f3126f13834ae2e7f381b3028e32\"},\"headline\":\"Three Ways to Increase the PHP Memory Limit\",\"datePublished\":\"2020-04-30T18:28:27+00:00\",\"dateModified\":\"2022-08-28T19:06:01+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/local.brightwhiz\/increase-php-memory-limit\/\"},\"wordCount\":440,\"publisher\":{\"@id\":\"http:\/\/local.brightwhiz\/#organization\"},\"image\":{\"@id\":\"http:\/\/local.brightwhiz\/increase-php-memory-limit\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2020\/04\/php-memory-limit.jpg\",\"keywords\":[\"Apache\",\"Internet\",\"Optimization\",\"Performance\",\"PHP\",\"Security\",\"Server\",\"Web\",\"Web Applications\",\"Web Development\",\"Websites\"],\"articleSection\":[\"Guides\",\"Programming\",\"Technology\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/local.brightwhiz\/increase-php-memory-limit\/\",\"url\":\"http:\/\/local.brightwhiz\/increase-php-memory-limit\/\",\"name\":\"Increase the PHP Memory Limit Using Three Easy Ways\",\"isPartOf\":{\"@id\":\"http:\/\/local.brightwhiz\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/local.brightwhiz\/increase-php-memory-limit\/#primaryimage\"},\"image\":{\"@id\":\"http:\/\/local.brightwhiz\/increase-php-memory-limit\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2020\/04\/php-memory-limit.jpg\",\"datePublished\":\"2020-04-30T18:28:27+00:00\",\"dateModified\":\"2022-08-28T19:06:01+00:00\",\"description\":\"Here is how to increase the PHP memory limit and avoid crashing your web applications using anyone of the three convenient ways\",\"breadcrumb\":{\"@id\":\"http:\/\/local.brightwhiz\/increase-php-memory-limit\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/local.brightwhiz\/increase-php-memory-limit\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/local.brightwhiz\/increase-php-memory-limit\/#primaryimage\",\"url\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2020\/04\/php-memory-limit.jpg\",\"contentUrl\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2020\/04\/php-memory-limit.jpg\",\"width\":1200,\"height\":630,\"caption\":\"PHP Memory Limit\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/local.brightwhiz\/increase-php-memory-limit\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/local.brightwhiz\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Three Ways to Increase the PHP Memory Limit\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/local.brightwhiz\/#website\",\"url\":\"http:\/\/local.brightwhiz\/\",\"name\":\"Brightwhiz.com\",\"description\":\"Best Tech guides, Tutorials, and News\",\"publisher\":{\"@id\":\"http:\/\/local.brightwhiz\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/local.brightwhiz\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"http:\/\/local.brightwhiz\/#organization\",\"name\":\"Brightwhiz\",\"url\":\"http:\/\/local.brightwhiz\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/logo\/image\/\",\"url\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/11\/brightwhiz-com-logo-orange.png\",\"contentUrl\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/11\/brightwhiz-com-logo-orange.png\",\"width\":706,\"height\":135,\"caption\":\"Brightwhiz\"},\"image\":{\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/brightwhiz\/\",\"https:\/\/x.com\/brightwhizmag\",\"https:\/\/instagram.com\/bright_whiz\/\",\"https:\/\/www.pinterest.com\/sobbayi\/\",\"https:\/\/www.youtube.com\/channel\/UC6sCdP_d_RiTIM7ErFT-PSQ\"]},{\"@type\":\"Person\",\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/person\/81f0f3126f13834ae2e7f381b3028e32\",\"name\":\"Michael Bright\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/1.gravatar.com\/avatar\/da90485875ff0aafa38fdd494abe87d1?s=96&d=mm&r=g\",\"contentUrl\":\"http:\/\/1.gravatar.com\/avatar\/da90485875ff0aafa38fdd494abe87d1?s=96&d=mm&r=g\",\"caption\":\"Michael Bright\"},\"sameAs\":[\"https:\/\/sobbayi.com\"],\"url\":\"http:\/\/local.brightwhiz\/author\/sobbayiadmin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Increase the PHP Memory Limit Using Three Easy Ways","description":"Here is how to increase the PHP memory limit and avoid crashing your web applications using anyone of the three convenient ways","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/local.brightwhiz\/increase-php-memory-limit\/","og_locale":"en_US","og_type":"article","og_title":"Increase the PHP Memory Limit Using Three Easy Ways","og_description":"Here is how to increase the PHP memory limit and avoid crashing your web applications using anyone of the three convenient ways","og_url":"http:\/\/local.brightwhiz\/increase-php-memory-limit\/","og_site_name":"Brightwhiz.com","article_publisher":"https:\/\/www.facebook.com\/brightwhiz\/","article_published_time":"2020-04-30T18:28:27+00:00","article_modified_time":"2022-08-28T19:06:01+00:00","og_image":[{"width":1200,"height":630,"url":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2020\/04\/php-memory-limit.jpg","type":"image\/jpeg"}],"author":"Michael Bright","twitter_card":"summary_large_image","twitter_creator":"@brightwhizmag","twitter_site":"@brightwhizmag","twitter_misc":{"Written by":"Michael Bright","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/local.brightwhiz\/increase-php-memory-limit\/#article","isPartOf":{"@id":"http:\/\/local.brightwhiz\/increase-php-memory-limit\/"},"author":{"name":"Michael Bright","@id":"http:\/\/local.brightwhiz\/#\/schema\/person\/81f0f3126f13834ae2e7f381b3028e32"},"headline":"Three Ways to Increase the PHP Memory Limit","datePublished":"2020-04-30T18:28:27+00:00","dateModified":"2022-08-28T19:06:01+00:00","mainEntityOfPage":{"@id":"http:\/\/local.brightwhiz\/increase-php-memory-limit\/"},"wordCount":440,"publisher":{"@id":"http:\/\/local.brightwhiz\/#organization"},"image":{"@id":"http:\/\/local.brightwhiz\/increase-php-memory-limit\/#primaryimage"},"thumbnailUrl":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2020\/04\/php-memory-limit.jpg","keywords":["Apache","Internet","Optimization","Performance","PHP","Security","Server","Web","Web Applications","Web Development","Websites"],"articleSection":["Guides","Programming","Technology"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"http:\/\/local.brightwhiz\/increase-php-memory-limit\/","url":"http:\/\/local.brightwhiz\/increase-php-memory-limit\/","name":"Increase the PHP Memory Limit Using Three Easy Ways","isPartOf":{"@id":"http:\/\/local.brightwhiz\/#website"},"primaryImageOfPage":{"@id":"http:\/\/local.brightwhiz\/increase-php-memory-limit\/#primaryimage"},"image":{"@id":"http:\/\/local.brightwhiz\/increase-php-memory-limit\/#primaryimage"},"thumbnailUrl":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2020\/04\/php-memory-limit.jpg","datePublished":"2020-04-30T18:28:27+00:00","dateModified":"2022-08-28T19:06:01+00:00","description":"Here is how to increase the PHP memory limit and avoid crashing your web applications using anyone of the three convenient ways","breadcrumb":{"@id":"http:\/\/local.brightwhiz\/increase-php-memory-limit\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/local.brightwhiz\/increase-php-memory-limit\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/local.brightwhiz\/increase-php-memory-limit\/#primaryimage","url":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2020\/04\/php-memory-limit.jpg","contentUrl":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2020\/04\/php-memory-limit.jpg","width":1200,"height":630,"caption":"PHP Memory Limit"},{"@type":"BreadcrumbList","@id":"http:\/\/local.brightwhiz\/increase-php-memory-limit\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/local.brightwhiz\/"},{"@type":"ListItem","position":2,"name":"Three Ways to Increase the PHP Memory Limit"}]},{"@type":"WebSite","@id":"http:\/\/local.brightwhiz\/#website","url":"http:\/\/local.brightwhiz\/","name":"Brightwhiz.com","description":"Best Tech guides, Tutorials, and News","publisher":{"@id":"http:\/\/local.brightwhiz\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/local.brightwhiz\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/local.brightwhiz\/#organization","name":"Brightwhiz","url":"http:\/\/local.brightwhiz\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/local.brightwhiz\/#\/schema\/logo\/image\/","url":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/11\/brightwhiz-com-logo-orange.png","contentUrl":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/11\/brightwhiz-com-logo-orange.png","width":706,"height":135,"caption":"Brightwhiz"},"image":{"@id":"http:\/\/local.brightwhiz\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/brightwhiz\/","https:\/\/x.com\/brightwhizmag","https:\/\/instagram.com\/bright_whiz\/","https:\/\/www.pinterest.com\/sobbayi\/","https:\/\/www.youtube.com\/channel\/UC6sCdP_d_RiTIM7ErFT-PSQ"]},{"@type":"Person","@id":"http:\/\/local.brightwhiz\/#\/schema\/person\/81f0f3126f13834ae2e7f381b3028e32","name":"Michael Bright","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/local.brightwhiz\/#\/schema\/person\/image\/","url":"http:\/\/1.gravatar.com\/avatar\/da90485875ff0aafa38fdd494abe87d1?s=96&d=mm&r=g","contentUrl":"http:\/\/1.gravatar.com\/avatar\/da90485875ff0aafa38fdd494abe87d1?s=96&d=mm&r=g","caption":"Michael Bright"},"sameAs":["https:\/\/sobbayi.com"],"url":"http:\/\/local.brightwhiz\/author\/sobbayiadmin\/"}]}},"_links":{"self":[{"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/posts\/8555"}],"collection":[{"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/comments?post=8555"}],"version-history":[{"count":0,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/posts\/8555\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/media\/8556"}],"wp:attachment":[{"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/media?parent=8555"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/categories?post=8555"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/tags?post=8555"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}