Welcome Guest, Not a member yet? Register   Sign In
Fatal error: memory exhausted in form validation
#1

[eluser]Kobus M[/eluser]
Hi everyone,

I hope someone can help. I am trying to do form validation with CI 2.1.3 (and might I add, it is very simple), but I am getting the memory allocation error shown below. I have done form validation in CI hundreds of time, but never got this error before.

Code:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 261904 bytes) in D:\xampp\htdocs\icms2_prototype\system\core\Config.php on line 45

The strange thing is, this error occurs in different places every time. Some times in config.php in core folder, other times in form_validation.php library, etc., it is not consistent.

Now - I understand that if the code was complex that you can easily run out of 128M of memory, but this is the simplest of all validations (no callbacks, just built-in rules):

Fro my form_validation.php config file:

Code:
<?php

    $config = array(
        'do_valida_client_update' => array (
            array (
                'field' => 'name',
                'label' => 'Name',
                'rules' => 'required'
            ),
            array (
                'field' => 'surname',
                'label' => 'Surname',
                'rules' => 'required'
            ),
            array (
                'field' => 'tel_sa',
                'label' => 'SA telephone number',
                'rules' => 'required|exact_length[10]|integer'
            ),
            array (
                'field' => 'email',
                'label' => 'E-mail address',
                'rules' => 'required|valid_email'
            ),
            array (
                'field' => 'sector',
                'label' => 'Sector',
                'rules' => 'required'
            ),
            array (
                'field' => 'region',
                'label' => 'Region',
                'rules' => 'required'
            )
        )
    );

?>

From my controller:

Code:
if ($this->form_validation->run('do_valida_client_update') !== FALSE)
{
    // Nothing in here yet
}
else
{
    // Nothing in here yet
}

As far as I can see this must work. I see no reason why it doesn't.

Any ideas would be great, thanks! :-) I am flabbergasted. What am I missing? :-(

Regards,

Kobus
#2

[eluser]InsiteFX[/eluser]
It may be the memory size limits in your php.ini file.
Code:
; Determines the size of the realpath cache to be used by PHP. This value should
; be increased on systems where PHP opens many files to reflect the quantity of
; the file operations performed.
; http://php.net/realpath-cache-size
realpath_cache_size = 32k

; Maximum amount of memory a script may consume (128MB)
; http://php.net/memory-limit
memory_limit = 256M

These two should match the memory size:

; Maximum size of POST data that PHP will accept.
; http://php.net/post-max-size
post_max_size = 128M

; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 128M
#3

[eluser]Kobus M[/eluser]
Hi InsiteFX,

My memory is set to 128M on my production server, and on my local server to 256M, both give the errors. This is the first time this actually happened. As I said, I have done this many times, and the first time I get an error.

I will see if there is something else causing non-sense, such as HTML structure or something.

Kobus
#4

[eluser]Kobus M[/eluser]
Nope - HTML is well-formed according to W3 Validor. Memory is set to 256M on local, 128M on production, this should work. I have even removed all rules but one, and I still get the error. Another form with only one rule works perfectly, and the code looks exactly the same. This is simply driving me nuts :-(

Thanks for trying InsiteFX.

Kobus
#5

[eluser]boltsabre[/eluser]
What other code do you have in your controller? Does it load any custom helpers or libraries, or models, or other methods? Do you have an infinite (or HUGE) loop somewhere that is hogging your memory?

Try turning your error reporting onto level 4 and check your error logs, try to pin point exactly where the memory reaches it's limit, and then back trace from there and try to find the leak.

If all else fails, delete the file (or method at the very least) and code it again, AKA, code-reboot.
#6

[eluser]Kobus M[/eluser]
Hi boltsabre,

The controller is too big to just delete (about 500 lines of code). The method itself is about 60 lines of code, and I am thinking of doing code-reboot myself, because there is just nothing about it that is wrong, as far as I can tell. Code fatigue, maybe? LOL. Well, your log idea has helped narrowing down the problem. Why it occurs though, I do not know... The log says:

"DEBUG - 2012-12-13 16:13:35 --> Unable to find validation rules"

Problem is - the rules are there. They work for another controller function, the array is well-formed, the array index name is the same everywhere. At least this is giving me something else to look at.

Thanks, boltsabre! :-)

Kobus

EDIT: Now that is not in the log anymore, and still errors. Oh well. code-reboot... :-)
#7

[eluser]CroNiX[/eluser]
I'd start troubleshooting by removing the config file stuff and try setting the rules manually in the controller. If you get that working add back piece by piece the rest of the code until you get it to error out.
#8

[eluser]Kobus M[/eluser]
Hi CroNiX,

Thanks for your reply. This is what I will do next. We will see how this turns out. To get the project out, I am currently relying only on client side validation. It is an internal project with only 4 users, though - so no biggie, but I do want to fix it over the long run :-)

Thanks,

Kobus
#9

[eluser]Kobus M[/eluser]
Hi guys,

Thanks for everyone that tried. I found my problem, and I am not 100% sure whether what I do is good or bad (comments please), but at least the problem is fixed.

I am leaning towards BAD, because at school. I learned that a function should have a single purpose. But I have since then read a few variations on that topic. Okay - herewith the details...

Here is how I do things usually (1 functions more than one possible outcome):

1. 1 controller/function performs the template display AS WELL AS the processing of the form (check if the form is submitted)
2. If submitted, then do something, if not submitted, then show the form
3. Function name is for example User/register (controller/function).

I have now split these functions (1 function for each outcome):

1. 1 controller function performs the template display (i.e., User/register).
2. 1 controller function performs the logic and form processing (i.e., User/register_submit).

When these functions are split up, I do not get the memory exhausted problem any more. I guess it is the check whether the form was submitted that caused an endless loop of some sort with the form_validation.

I believe that this ended up being my error, but I am marking it as a solution in the event that someone else finds themselves in this same situation.

Thanks for trying!

Kobus




Theme © iAndrew 2016 - Forum software by © MyBB