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 531039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:15:34+00:00 2026-05-13T09:15:34+00:00

I’m aware that serializing is used to convert data types into a storable format,

  • 0

I’m aware that serializing is used to
convert data types into a storable
format, for purposes such as caching.

What I’m more specifically asking is, what are the circumstances in which you should actually decide to store data ( using serialize() in PHP, pickle module in Python, et cetera )?

Let’s say we had a high traffic website, and in our /blog page we are using static content xml files, a gettext mo file, and dynamically generated content from a database.

Example #1:

The file we rely on for static content is en/blog.xml:

'<content><![CDATA[
<h1>Welcome to my blog!</h1>
<p>Lorem ipsum dolor sit amet..</p>

]]></content>'

Would we want to serialize this xml file itself and store it in cache?

Example #2:

We also have a dynamically generated form, normally I would assume I would not serialize anything because it’s server-side generated and dynamic, but our form field labels are internationalized and the user requested this page in spanish, therefore we are using a translation class which grabs form field labels stored in mo/csv/xml format.

Contents of contact-us.php:

<label for="first_name"><?php echo $L->_("First Name");?></label>
<input id="first_name" name="first_name" type="text">

The “First Name” message id translation is pulled from the application-level translation file, which we parse and store in an array which resides in our translation class. So it would be ideal for our code to not parse the mo file on every page request, and instead serialize the whole array after parsing the mo, and then rely on the serialized dump of that?

Example #3:

Let’s say on our blog page we’re pulling in the 5 most recent blog posts.

$posts = BlogClass->sql('SELECT blog_message, blog_author FROM blog_posts LIMIT 5 ORDER BY blog_date DESC');

Would we want to rely on something like memcache and just set a key to the result of the sql statement, would it serialize the results of the query, or?

Bonus:

If anyone could actually provide specific examples of efficient/practical uses/mis-uses of serialization, that’d be great – something like a multi-page, huge huge form that pulls in database information and stores stuff in sessions, or any examples where you had to rely on serialize..

  • 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-13T09:15:34+00:00Added an answer on May 13, 2026 at 9:15 am

    Example 1

    Profile.

    • Is it prohibitively costly to generate your content pages?
    • Is it significantly less costly to deserialize your generated content?

    If both answers are yes, consider it.

    Example 2

    Profile.

    • Is it prohibitively costly to generate your content pages?
    • Is it significantly less costly to deserialize your generated content?

    If both answers are yes, consider it.

    Example 3

    Profile.

    • Is that query prohibitively expensive?
    • Is it significantly faster to grab the data from memcached?

    If both answers are yes, consider it.

    Bonus

    I never serialize my data just because I can. I need to have a reason to do so, otherwise it’s just premature optimization. There are several factors that come into deciding whether this should be done.

    Performing sorting or other operations on a serialized set of data

    This will almost always be a bad idea. e.g. if you serialized a resultset from a database, then needed to reorder this set by some field, you’re shooting yourself in the foot.

    Messaging

    If you need to communicate serialized data to other services/languages then choice of serialization is critical. I avoid serializing using a language specific method if I know or think that other things may need to read it. JSON is often an ideal format for cross language serialization.

    Updating serialized data

    You have to be willing to regenerate the serialized data for updates to it’s source. It will be prohibitively expensive to do any type of complex updates to the serialized data.

    Human readability

    If you need to read it easily, I suggest avoiding language specific formats. I suggest JSON for this.

    Edit:

    I just looked again at the query in Example 3. That is an extremely simple query, you’re only selecting 2 fields, and ordering by a date field. With a properly indexed table this query should be trivial, and I would not suggest caching something like this into memcached.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer One way to do this is to expose the logic… May 13, 2026 at 12:22 pm
  • Editorial Team
    Editorial Team added an answer First of all, I would use file_put_contents (http://php.net/manual/en/function.file-put-contents.php), it essentially… May 13, 2026 at 12:22 pm
  • Editorial Team
    Editorial Team added an answer After farther investigation the problem was with jquery submit() handling… May 13, 2026 at 12:22 pm

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want use html5's new tag to play a wav file (currently only supported
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I've got a string that has curly quotes in it. I'd like to replace
In order to apply a triggered animation to all ToolTip s in my app,

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.