Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 314443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:12:01+00:00 2026-05-12T08:12:01+00:00

I am curious, is there a size limit on serialize in PHP. Would it

  • 0

I am curious, is there a size limit on serialize in PHP. Would it be possible to serialize an array with 5,000 keys and values so it can be stored into a cache?

I am hoping to cache a users friend list on a social network site, the cache will need to be updated fairly often but it will need to be read almost every page load.

On a single server setup I am assuming APC would be better then memcache for this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T08:12:01+00:00Added an answer on May 12, 2026 at 8:12 am

    As quite a couple other people answered already, just for fun, here’s a very quick benchmark (do I dare calling it that ? ) ; consider the following code :

    $num = 1;
    
    $list = array_fill(0, 5000, str_repeat('1234567890', $num));
    
    $before = microtime(true);
    for ($i=0 ; $i<10000 ; $i++) {
        $str = serialize($list);
    }
    $after = microtime(true);
    
    var_dump($after-$before);
    var_dump(memory_get_peak_usage());
    

    I’m running this on PHP 5.2.6 (the one bundled with Ubuntu jaunty).

    And, yes, there are only values ; no keys ; and the values are quite simple : no object, no sub-array, no nothing but string.

    For $num = 1, you get :

    float(11.8147978783)
    int(1702688)
    

    For $num = 10, you get :

    float(13.1230671406)
    int(2612104)
    

    And, for $num = 100, you get :

    float(63.2925770283)
    int(11621760)
    

    So, it seems the bigger each element of the array is, the longer it takes (seems fair, actually). But, for elements 100 times bigger, you don’t take 100 times much longer…

    Now, with an array of 50000 elements, instead of 5000, which means this part of the code is changed :

    $list = array_fill(0, 50000, str_repeat('1234567890', $num));
    

    With $num = 1, you get :

    float(158.236332178)
    int(15750752)
    

    Considering the time it took for 1, I won’t be running this for either $num = 10 nor $num = 100…

    Yes, of course, in a real situation, you wouldn’t be doing this 10000 times ; so let’s try with only 10 iterations of the for loop.

    For $num = 1 :

    float(0.206310987473)
    int(15750752)
    

    For $num = 10 :

    float(0.272629022598)
    int(24849832)
    

    And for $num = 100 :

    float(0.895547151566)
    int(114949792)
    

    Yeah, that’s almost 1 second — and quite a bit of memory used ^^

    (No, this is not a production server : I have a pretty high memory_limit on this development machine ^^ )

    So, in the end, to be a bit shorter than those number — and, yes, you can have numbers say whatever you want them to — I wouldn’t say there is a “limit” as in “hardcoded” in PHP, but you’ll end up facing one of those :

    • max_execution_time (generally, on a webserver, it’s never more than 30 seconds)
    • memory_limit (on a webserver, it’s generally not muco more than 32MB)
    • the load you webserver will have : while 1 of those big serialize-loop was running, it took 1 of my CPU ; if you are having quite a couple of users on the same page at the same time, I let you imagine what it will give 😉
    • the patience of your user ^^

    But, except if you are really serializing long arrays of big data, I am not sure it will matter that much…

    And you must take into consideration the amount of time/CPU-load using that cache might help you gain 😉

    Still, the best way to know would be to test by yourself, with real data 😉

    And you might also want to take a look at what Xdebug can do when it comes to profiling : this kind of situation is one of those it is useful for!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 231k
  • Answers 231k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use the following function like this: Image('/path/to/original.image', '1/1', '150*', './thumb.jpg');… May 13, 2026 at 2:13 am
  • Editorial Team
    Editorial Team added an answer Check you database schema to see if the field (referenced… May 13, 2026 at 2:13 am
  • Editorial Team
    Editorial Team added an answer I figured out the problem - there was a session… May 13, 2026 at 2:13 am

Related Questions

I am using jquery, JSON, and AJAX for a comment system. I am curious,
Is there a way to enforce/limit the types that are passed to primitives? (bool,
I have approximately 30 variadic functions. Each one accepts a path as the final
I also have a desktop application written in Windows Forms that is a middling

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.