Connecting Tech Pros Worldwide Help | Site Map

print_r and large arrays

 
LinkBack Thread Tools Search this Thread
  #1  
Old March 6th, 2006, 02:55 PM
meltedown
Guest
 
Posts: n/a
Default print_r and large arrays

Normally, if I use
$result=print_r($array,TRUE);
print_r prints nothing and $result is equal to the readable array.

However, if $array is very large, print_r prints the array and returns
nothing.

Is this correct ? I don't see anything about this in the the manual.

I have tried limiting the size to array to see exactly how large the
array has to be to trigger this behavior, but the exact size seems to be
variable or it depends on some other factor. Can anyone explain what is
the deciding factor ?

  #2  
Old March 8th, 2006, 04:15 AM
Carl Vondrick
Guest
 
Posts: n/a
Default Re: print_r and large arrays

meltdown wrote:[color=blue]
> Normally, if I use
> $result=print_r($array,TRUE);
> print_r prints nothing and $result is equal to the readable array.
>
> However, if $array is very large, print_r prints the array and returns
> nothing.
>
> Is this correct ? I don't see anything about this in the the manual.
>
> I have tried limiting the size to array to see exactly how large the
> array has to be to trigger this behavior, but the exact size seems to be
> variable or it depends on some other factor. Can anyone explain what is
> the deciding factor ?[/color]
You can use output buffering to get around this.

Just do:

ob_start();
print_r($array);
$value = ob_get_flush(); // or something like that!

I'm not sure why your problem is happening, but have you checked memory?
I bet it is a memory issue.

--
Carl Vondrick
www.carlsoft.net
usenet [at] carlsoft [dot] net
  #3  
Old March 9th, 2006, 03:55 PM
meltedown
Guest
 
Posts: n/a
Default Re: print_r and large arrays

Carl Vondrick wrote:[color=blue]
> meltdown wrote:[color=green]
>> Normally, if I use
>> $result=print_r($array,TRUE);
>> print_r prints nothing and $result is equal to the readable array.
>>
>> However, if $array is very large, print_r prints the array and returns
>> nothing.
>>
>> Is this correct ? I don't see anything about this in the the manual.
>>
>> I have tried limiting the size to array to see exactly how large the
>> array has to be to trigger this behavior, but the exact size seems to
>> be variable or it depends on some other factor. Can anyone explain
>> what is the deciding factor ?[/color]
> You can use output buffering to get around this.
>
> Just do:
>
> ob_start();
> print_r($array);
> $value = ob_get_flush(); // or something like that![/color]

OK thanks.[color=blue]
>
> I'm not sure why your problem is happening, but have you checked memory?
> I bet it is a memory issue.
>[/color]

I assum you mean memory on the server. How do I check that ?
  #4  
Old March 10th, 2006, 06:25 AM
Carl Vondrick
Guest
 
Posts: n/a
Default Re: print_r and large arrays

meltedown wrote:[color=blue]
> I assum you mean memory on the server. How do I check that ?[/color]

The best way is to use SSH and run the top command. This will display
the process information.

If you do not have SSH access, then try this:
http://www.php.net/manual/en/functio...-get-usage.php

--
Carl Vondrick
www.carlsoft.net
usenet [at] carlsoft [dot] net
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.