Friday, 19 August 2016

How to Solve PHP Fatal error: Allowed memory size of 8388608 bytes exhausted

One of the most common and frustrating errors encountered by PHP coders reads: “Fatal error: Allowed memory size of 8388608 bytes exhausted…” followed by something like “(tried to allocate XXXX bytes) in /home/www/file.module on line 12.” This fatal PHP error crops up because, by default, PHP has a memory usage limit of 8 MB for any given script. This is a good thing, actually, because you don’t want a rogue PHP script to bring down your server by hogging all the memory. But occasionally, you’ll have a PHP script that normally exceeds the 8 MB limit (say, for importing or uploading). To workaround the “Fatal error: Allowed memory size of 8388608 bytes exhausted…” error message, simply insert this line of code into your script at the top:
ini_set(“memory_limit”,”16M“);





This will set your memory limit to 16 MB, rather than 8 MB. You can, and should, fiddle with this number so that it is as low as possible without repeating that error message. This will only alter the memory limit for that particular PHP file.
Alternately, you can alter your php.ini file to up the memory limit. This will affect all scripts on your server. Simply open php.ini and find the line that reads “memory_limit” and alter it:
memory_limit=16M

I’ve noticed in my own PHP.ini file that my default is much higher at 128M. So, if I were to ever receive this error message it would read: “Fatal error: Allowed memory size of 134217728 bytes exhausted…” and obviously be a much bigger problem. But it has the same workaround as “Fatal error: Allowed memory size of 8388608 bytes exhausted…” or “Fatal error: Allowed memory size of 16777216 bytes exhausted…” or whatever. Apparently, the  memory_limit default was upped  from 8M to 16M in PHP 5.2.0 and is now 128M for PHP 5.3.0, which would explain why you may not get this error message at all.

You can also disable the memory limit by setting memory_limit to –1 in PHP.ini.
memory_limit=-1
This isn’t usually a good idea, though, for obvious reasons.
Note: You can also use the memory_limit line in your .htaccess page.
Now, remember, this is only a workaround. Really, your PHP script should not be exceeding 8 MB, unless your uploading files or doing something else that’s obviously taking up a lot of memory usage. What you should really be doing is trying to figure out why your script is using so much memory and attempt to fix it. One way to figure out how much memory your PHP script is using is to use the memory_get_usage() PHP function. Simply echo it at any point in your script to find out where your memory usage is spiking:
echo memory_get_usage();
If you’re getting this error message in Drupal or Joomla, the likely culprit is a new module or package. For example, in Drupal, the admin/modules page loads every module in your Drupal installation, which can get hairy if a custom module is buggy, corrupt or hacked. Try disabling modules one by one to identify which is bringing the party down. Also, some hosting providers will ignore your attempts to modify the memory limits for your PHP code so you might need to contact your hosting support to assist you. I’ve found sometimes I need to edit the php.ini file and sometimes put the code into the .htaccess file. Either way, hopefully this info here is enough to get you on your way!

Sunday, 7 August 2016

CodeIgniter 4 Development

What is CodeIgniter?

CodeIgniter is a PHP full-stack web framework that is light, fast, flexible, and secure. More information can be found at the official site.
This repository holds the pre-alpha code for CodeIgniter 4 only. Version 4 is a complete rewrite to bring the quality and the code into a more modern version, while still keeping as many of the things intact that has made people love the framework over the years.
This is pre-release code and should not be used in production sites.
More information about the plans for version 4 can be found in the announcement on the forums.

Important Change with index.php

index.php is no longer in the root of the project! It has been moved inside the public folder, for better security and separation of components.
This means that you should configure your web server to "point" to your project's public folder, and not to the project root. A better practice would be to configure a virtual host to point there. A poor practice would be to point your web server to the project root and expect to enter public/..., as the rest of your logic and the framework are exposed.
Please read the user guide for a better explanation of how CI4 works! The user guide updating and deployment is a bit awkward at the moment, but we are working on it!

Repository Management

We use Github issues to track BUGS and to track approved DEVELOPMENT work packages. We use our forum to provide SUPPORT and to discuss FEATURE REQUESTS.
If you raise an issue here that pertains to support or a feature request, it will be closed! If you are not sure if you have found a bug, raise a thread on the forum first - someone else may have encountered the same thing.
Before raising a new Github issue, please check that your bug hasn't already been reported or fixed.
We use pull requests (PRs) for CONTRIBUTIONS to the repository. We are looking for contributions that address one of the reported bugs or approved work packages.
Do not use a PR as a form of feature request. Unsolicited contributions will only be considered if they fit nicely into the framework roadmap. Remember that some components that were part of CodeIgniter 3 are being moved to optional packages, with their own repository.

Contributing

We are accepting contributions from the community, specifically those identified as part of phase 2.
We will try to manage the process somewhat, by adding a "Help wanted" label to those that we are specifically interested in at any point in time. Join the discussion for those issues, and let us know if you want to take the lead for one of them.
We are not looking for out-of-scope contributions, only those that would be considered part of our controlled evolution!
Please read the Contributing to CodeIgniter section in the user guide

Server Requirements

PHP version 7 or higher is required.

Running CodeIgniter Tests

Information on running CodeIgniter test suite can be found in the README.md file in the tests directory.

 https://github.com/bcit-ci/CodeIgniter4