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

  • Home
  • SEARCH
  • 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 8561797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:35:03+00:00 2026-06-11T16:35:03+00:00

here is my dilemma : I am creating a multilingual platform. In that purpose

  • 0

here is my dilemma :

I am creating a multilingual platform. In that purpose I created json files containing all the translated text for each language.

Now when the user land on a their page I read from that file and store the array of translations in the $_SESSION variable such as

$_SESSION['website_text'] = json_decode(file_get_contents("content_".$language.".json"), true);

Then everytime I want to echo text on the views I access the element from the session array :

$text = $_SESSION['website_text']['paragraph2_headline'];

Now I am wondering, since the $_SESSION is stored on the server. Is it faster to read from the session like I do or to read everytime from the file and decode the json?
The second option would go like that :

$website_text = json_decode(file_get_contents("content_".$language.".json"), true);
$text =  $website['paragraph2_headline'];

Thank you all for your help!

  • 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-06-11T16:35:05+00:00Added an answer on June 11, 2026 at 4:35 pm

    Most likely it’s faster when pulling the data from $_SESSION, but $_SESSION is not a good place to store localization data in because it will end up being duplicated for each user.

    When you retrieve the strings from $_SESSION then PHP has to read the data from the session file (which it already does to read any other session data, so the cost of opening the file is somewhat amortized) and run unserialize on it; if you retrieve it from a JSON file then it has open the file, read it and run json_decode. unserialize should be faster than json_decode, but please don’t quote me on that.

    If you are interested in making this fast, it would be better to read the strings directly from a PHP file where they are stored as an array:

    // content_en.php
    <?php
    return array(
        'welcome' => 'Welcome to our website!',
        // ...
    );
    

    Even if your localization files are in JSON it would be very easy to “compile” the JSON into PHP and use the PHP code as a cache:

    $lang = 'en';
    
    $sourceFile = 'content_'.$lang.'.json';
    $cacheFile = 'content_'.$lang.'.cache.php';
    if (!is_file($cacheFile)) {
        $content = json_decode(file_get_contents($sourceFile), true);
        file_put_contents($cacheFile, "<?php\n return ".var_export($content, true).";");
    }
    else {
        $content = include($cacheFile);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my dilemma. I have 2 animations that need to run sequentially. The first
Here is my dilemma: The Problem I have SubProgram (a DLL) that uses System.Data.SQLite
Here is my dilemma. I have a collection of entities that I want to
So here is my dilemma. I have created a rails scaffold named posts for
I have a bit of a dilemma here. I have an app that has
So here is my dilemma, I have a navigation controller that controls three views.
Note that I'm 95% unfamiliar with pointers. So here's my dilemma, I have a
I have a bit of a dilemma here. I have a drupal 7 database
Here is the Javascript I currently have <script type=text/javascript> $(function() { $('.slideshow').hover( function() {
Here is the script I'm using, copied directly from Google: <script type=text/javascript> var _gaq

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.