save_array too large?
Page 1 of 2 12 LastLast
Results 1 to 15 of 25

Thread: save_array too large?

  1. #1
    Junior Member
    Join Date
    Nov 2007
    Posts
    19

    save_array too large?

    Hello and greetings. My first post of probably many i am sure

    What I have here is an array that gets hung up when doing very large amounts of data.

    if (isset($_GET['add_sec'])) {
    $sections[] = array(
    'top_x' => @$_GET['top_x'],
    'top_y' => @$_GET['top_y'],
    'bot_x' => @$_GET['bot_x'],
    'bot_y' => @$_GET['bot_y'],
    'pat' => @$_GET['pat'],
    'seed' => @$_GET['seed'],
    'seed2' => @$_GET['seed2'],
    'type' => @$_GET['type'],
    'anim' => @implode('|',$vAnimArray),
    'tree' => @implode('|',$vTreeArray),
    'deco' => @implode('|',$vDecoArray),
    'building' => @implode('|',$vBuildingArray),
    'buyanim' => @$_GET['buyanim'],
    'buytree' => @$_GET['buytree'],
    'buydeco' => @$_GET['buydeco'],
    'buybuilding' => @$_GET['buybuilding'],
    'active' => @$_GET['active'],
    'place' => @$_GET['place'],
    'rotate' => @$_GET['rotate'],
    'walk' => @$_GET['walk']
    );
    save_array($sections, 'sections.txt');
    }

    I have quite a few of these arrays (different plugins) that do the exact same thing when it comes to writing a very large amount of data to the text file. They work fine when it's small to medium amount of data. Any ideas on this? Is there a cap size for the text file? Looking for any suggestions at all

  2. #2
    Senior Member traq's Avatar
    Join Date
    Jun 2011
    Location
    so.Cal
    Posts
    949
    what do you mean by "large"?
    what does save_array() do?

    It would depend heavily on your server and what resources your hosting plan allows you, as well.

    I can't help but wonder why you wouldn't use a database for this...?

  3. #3
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,395
    I would echo everything in traq's post (especially the question about why you aren't using a database for this), but I would also ask what you mean by "gets hung up" ?

  4. #4
    Junior Member
    Join Date
    Nov 2007
    Posts
    19
    Sorry I am not the author of the plugin, and the author is MIA.
    The plugin is used by a program. When the program is open, I can access it also via http://127.0.0.1:3001/plugins/Sections/main.php

    http://i1231.photobucket.com/albums/...tionsDiag1.png

    When selecting just a few animals and save it writes the text fine. But when I check all animals and save it refreshes and comes back as a white screen (aka white screen of death).

  5. #5
    Junior Member
    Join Date
    Nov 2007
    Posts
    19
    By the way, it appears to be "flooding" out per say. When all animals are selected, and save, white screen shows instead of the normal load_array. It doesn't not even make the text file.

  6. #6
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,395
    Enable error logging if it isn't already, make sure error_reporting is set to E_ALL, and check the error log for any errors. It's possible you're getting a fatal error due to being out of memory or something like that.

  7. #7
    Senior Member traq's Avatar
    Join Date
    Jun 2011
    Location
    so.Cal
    Posts
    949
    Quote Originally Posted by boujii View Post
    The plugin is used by a program. When the program is open, I can access it also via http://127.0.0.1:3001/plugins/Sections/main.php
    [ ... ]
    When selecting just a few animals and save it writes the text fine. But when I check all animals and save it refreshes and comes back as a white screen (aka white screen of death).
    SO,

    this is on your local machine, correct (not online)?

    Are you using the plugin via the program you refer to, or in your web browser?

    Is this "white screen of death" actually freezing your browser (or your computer)?
    Or is it simply a blank page (no response from the plugin script)?


    As brad says, start by enabling error reporting. From there, you need to try to narrow down what might be causing this --

    how large are the arrays you're passing to 'anim', 'tree', 'deco', and 'building'?

    How many elements are there in the $sections array?

    Can you find the definition for your save_array() function, so we can see what it actually does?

  8. #8
    Junior Member
    Join Date
    Nov 2007
    Posts
    19
    Quote Originally Posted by bradgrafelman View Post
    Enable error logging if it isn't already, make sure error_reporting is set to E_ALL, and check the error log for any errors. It's possible you're getting a fatal error due to being out of memory or something like that.
    error_reporting = E_ALL & ~E_NOTICE
    display_errors = On
    display_startup_errors = On
    log_errors = On
    ignore_repeated_errors = Off
    ignore_repeated_source = Off
    report_memleaks = On
    track_errors = On

    But having an issue locating the actual log. The php.ini itself is in the program root directory.

  9. #9
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,395
    Quote Originally Posted by boujii View Post
    But having an issue locating the actual log.
    You'll want to examine the error_log PHP directive to determine that.

    Quote Originally Posted by boujii View Post
    The php.ini itself is in the program root directory.
    And you're sure that's the one being parsed? Do a phpinfo() and verify 1) the settings you listed above coincide with the values printed in the tables, and b) the 'Loaded Configuration File' points to the same php.ini file you're talking about.

  10. #10
    Junior Member
    Join Date
    Nov 2007
    Posts
    19
    That helped TY. The php.ini was missing the error_log. And yes settings for phpinfo() are pointing to correct .ini
    Now it is also making and writing the error.log

    This is what I have as far as error reporting now.

    error_reporting = E_ALL | E_STRICT
    display_errors = On
    display_startup_errors = On
    log_errors = On
    html_errors = On
    output_buffering = 4096
    ignore_repeated_errors = Off
    ignore_repeated_source = Off
    report_memleaks = On
    track_errors = On
    error_log = error.log


    Now I do have an error in the log showing
    [19-Apr-2012 13:57:41] PHP Notice: Undefined offset: 1 in C:\2.1\parser.php on line 2862

    But that is a completely different php and has no bearing on the current php I am working with. After clicking SAVE no error is logged by still returns white screen. Any more suggestions?

  11. #11
    Junior Member
    Join Date
    Nov 2007
    Posts
    19
    The thing I don't understand is I would think if there was an error in the code, it would error all the time, not just when doing massive amounts of data in the array. I mean, for instance, I could select 300 animals and work fine, but if more then 500 I get the white screen. So I would think it be a performance issue. Since no error is showing, perhaps the php is crashing? And like I said, this pertains to multiple plugins whereas selecting massive amounts of things for the array it happens. I tried changing a few things in the php.ini but no luck as of yet.

  12. #12
    Junior Member
    Join Date
    Nov 2007
    Posts
    19
    I seen this somewhere.. Think this could be what's happening?

    "You're hitting the max number of array elements.
    This is 'fixed' in PHP5 where there can be more elements in an array. It has nothing to do with the file size.
    "

  13. #13
    Senior Member traq's Avatar
    Join Date
    Jun 2011
    Location
    so.Cal
    Posts
    949
    No: there is no "max number of array elements."

    PHP does have a maximum amount of memory it's allowed to allocate while executing. If your arrays are very large, you might be overrunning this limit while trying to write the values to file.

    Likewise, if your computer is taking too long to complete the writing, you might be overrunning your max execution time.

  14. #14
    Junior Member
    Join Date
    Nov 2007
    Posts
    19
    Quote Originally Posted by traq View Post
    SO,

    this is on your local machine, correct (not online)?

    Are you using the plugin via the program you refer to, or in your web browser?

    Is this "white screen of death" actually freezing your browser (or your computer)?
    Or is it simply a blank page (no response from the plugin script)?


    As brad says, start by enabling error reporting. From there, you need to try to narrow down what might be causing this --

    how large are the arrays you're passing to 'anim', 'tree', 'deco', and 'building'?

    How many elements are there in the $sections array?

    Can you find the definition for your save_array() function, so we can see what it actually does?
    The program uses IE as it's browser. But once program is open, I can open it manually in any browser. When saving the array that is extremely large, result is same on all browsers (IE, Chrome, Opera).

    It does not freeze me at all. Rather the white screen is instant. When it is saving a normal amount of data, it takes a few seconds, probably because it then load_array again as a refresh per say. The second I hit SAVE for the

    Code:
        if (isset($_GET['add_sec'])) {
        $array_size = count($sections);
        for($i = 0; $i < $array_size; $i++)
        {
          $sections[] = array(
            'top_x' => @$_GET['top_x'],
            'top_y' => @$_GET['top_y'],
            'bot_x' => @$_GET['bot_x'],
            'bot_y' => @$_GET['bot_y'],
            'pat'  => @$_GET['pat'],
            'seed'  => @$_GET['seed'],
            'seed2' => @$_GET['seed2'],
            'type'  => @$_GET['type'],
            'anim'  => @implode('|',$vAnimArray),
            'tree'  => @implode('|',$vTreeArray),
            'deco'  => @implode('|',$vDecoArray),
            'building'  => @implode('|',$vBuildingArray),
            'buyanim'  => @$_GET['buyanim'],
            'buytree'  => @$_GET['buytree'],
            'buydeco'  => @$_GET['buydeco'],
            'buybuilding'  => @$_GET['buybuilding'],
            'active' => @$_GET['active'],
            'place' => @$_GET['place'],
            'rotate' => @$_GET['rotate'],
            'walk' => @$_GET['walk']
            );
    	echo $array_size;
          save_array($sections, 'sections.txt');
          }
        }
    It's white screen immediately. The sections.txt is also never even created.

    I am trying to get a way to "count" by throwing an
    $array_size = count($sections);
    for($i = 0; $i < $array_size; $i++)
    but have not worked out the echo yet for it. Sorry novice php lol.

    Error reporting shows no error as it seems to crash immediately.

  15. #15
    Junior Member
    Join Date
    Nov 2007
    Posts
    19
    Quote Originally Posted by traq View Post
    No: there is no "max number of array elements."

    PHP does have a maximum amount of memory it's allowed to allocate while executing. If your arrays are very large, you might be overrunning this limit while trying to write the values to file.

    Likewise, if your computer is taking too long to complete the writing, you might be overrunning your max execution time.
    This I thought as well. So my current php.ini is for testing purposes.
    max_execution_time = 3600
    max_input_time = 3600
    ;max_input_nesting_level = 64 ; Maximum input variable nesting level
    memory_limit = 2048M

    This is run on a I7 with 9GB of memory on a windows 7 ultimate platform. Result is same on Windows XP dual core with 2gb memory.

    OK the heart of the matter is:
    This is a program for Farmville on Facebook. The program can contain several plugins. A lot of the plugins result in the same white screen when doing a very large array. Probably because they are written similarly I'm sure. So there are hundreds of people using this program (aka bot). So the white screen issue is very common. The actually program itself uses sqlite. But as you see the plugins are all coded to write to a text file rather then their own sqlite database.
    Last edited by boujii; 04-20-2012 at 12:09 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •