Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

danWilcz's avatar

print_r($request) causes out of memory error.

Hi,

When I do print_r($request); exit(); for my request.

I get the following error in my log:

[2017-09-06 15:19:44] production.ERROR: Symfony\Component\Debug\Exception\FatalErrorException: Allowed memory size of 134217728 bytes exhausted (tried to allocate 90181632 bytes) in [path to file reducted] Stack trace: #0 {main}

Why on earth would printing out the request array use so much memory? That can not be right can it?

This happens for all my requests, I am posting a simple string from a form. I am trying to print the request array right after getting into my controller.

0 likes
13 replies
danWilcz's avatar

Hi jack did that and all I got was:

array:5 [▼ "_token" => "string that I reducted" "user_id" => "1" "subject" => "Account Activation" "description" => "yolo" "q" => "/control/email" ]

JackJones's avatar

My bad, I assumed that was what you meant by the request array, what info are you trying to get?

danWilcz's avatar

Incidently I am not sure what is the q parameter. I do not put it there but it seems to be on all my requests but only in production not in development.

danWilcz's avatar

My bad, I assumed that was what you meant by the request array, what info are you trying to get?

I am just trying to debug my app.

I was trying to save the data from the request to the database but I got an error on production because of the 'q' parameter that appears from nowhere.

In trying to debug I tried to print_r the request, but I got out of memory error and just wondering if its normal, I can imagine why print_r($request) would cause out of memory.

Jaytee's avatar

Are you using some kind of search in your application by any chance?

EDIT: Yeah the q value is coming from your form. Seems like its being passed in the query string, which is the result of a GET request.

danWilcz's avatar

Yeah the q value is coming from your form. Seems like its being passed in the query string, which is the result of a GET request.

But I am not passing any q parameter, and it only happens in production not development, for the same code.

I wonder if its some sort of client side browser thing but I tried different browsers and get same result.

danWilcz's avatar

What does your form look like?

               <form method="POST" action="https://www.mydomain/control/email" accept-charset="UTF-8" class="form-horizontal" id="email-user-form"><input name="_token" type="hidden" value="reducted">

                <input id="user-id" name="user_id" type="hidden">

                <div class="form-group">
                    <label class="col-md-3 control-label" for="subject">Subject</label>
                    <div class="col-md-9">
                        <input id="subject" class="form-control" placeholder="Email Subject" name="subject" type="text">
                    </div>
                    <span class="formerror"></span>
                </div>

                <div class="form-group">
                    <label class="col-md-3 control-label" for="message">Message</label>
                    <div class="col-md-9">
                        <textarea id="description" class="form-control" placeholder="Message Body" rows="3" name="description" cols="50"></textarea>
                    </div>
                    <span class="formerror"></span>
                </div>

                </form>
Snapey's avatar
Snapey
Best Answer
Level 122

print_r tends to get itself in a recursion situation. Better to use dump() if you want execution to continue or dd() if you want it to stop

Please or to participate in this conversation.