1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

is there any other way to save arrays when server restarts

Discussion in 'Development' started by Levi, Jun 22, 2018.

  1. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    i currently save datas in array to config on disable and load them on enable. is there any other method to saving arrays when server restarts or closes?
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    An array of what
     
  3. Aviv

    Aviv Baby Zombie

    Messages:
    156
    You can use the serialize() and unserialize() or json_encode() and json_decode() (EDIT: You can also use yaml_emit() or yaml_parse()) to save to file when plugin enables and load from file when it disables, This is kinda the same concept except it allowes you to store big objects.
    NOTE:
    NEVER serialize pocketmine's object, for more info, go to this thread: https://forums.pmmp.io/threads/why-not-to-serialize-objects-for-storage.5614/
     
  4. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    array of player and their money
     
  5. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    PHP arrays aren't the best in terms of memory consumption. You are fine if the number of entries in the array is not much (a million entries should be okay) PROVIDED you are not looping through the array or sorting it frequently.

    I'd recommend you store your data into a database, such as MySQL and MongoDB. These databases are designed to hold millions of entries and process get/sets in just as much time as it would take with one entry in the database.

    P.S. Do not query server-based databases on the main thread.
     
  6. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    Is MongoDB a database like mysql but hosted online?
     
  7. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Both — MongoDB and MySQL are server-based, you can connect to them from anywhere.

    This should be a good time for you to learn SQL. Also check out the libasynql virion which provides a simple async API for MySQL queries.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.