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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:40:20+00:00 2026-06-12T16:40:20+00:00

I am currently trying to process a relatively large log file which stores game

  • 0

I am currently trying to process a relatively large log file which stores game information in JSON. Any log file averagly ranges from 2000-5000 lines.

Example output (retaining formatting…) from the logfile, note: I have removed the players name, SteamID and Ip Address for his own privacy:

{"timestamp": "2012-09-16 14:10:36", "event": "log_start", "unixTime": 1347768636}
{"timestamp": "2012-09-16 14:10:36", "event": "player_status", "player": {"name": "PLAYER NICKNAME", "userId": 15, "uniqueId": "STEAM_X:X:XXXXXXX (STEAMID)", "team": 1}, "address": "xxx.xxx.xxx.xxx (IP)", "country": "AU"}
{"timestamp": "2012-09-16 14:10:36", "event": "live_on_3", "map": "de_mirage_csgo", "teams": [{"name": "Terrorists", "team": 2}, {"name": "Counter-Terrorists", "team": 3}], "status": 5, "version": "1.0.0 Beta"}

This is where the problem begins. Each line of the log file effectively defines a new JSON object? I am trying to decode all of these objects (storing them as associative arrays) line by line (json_decode($string,TRUE) and from there on I try to merge them into one PHP array through a loop. This does ‘work’ (in the sense there is no visual error), but array_merge doesn’t produce anything near the results I expected. This is my code:

/* parse the logfile into array */
for ($i = 0; $i < $lineCount; $i++) {
    if ($i === 0) { // first iteration
        $arrLog = json_decode($line[$i],true);     
    } else {
        $arrTempLog = json_decode($line[$i],true); // create temp array to store each line
        $arrLog = array_merge($arrLog, $arrTempLog); // merge temp array w/ main array    
    }
} 

Any suggestions or input which would lead me in the right direction to achieving what I need would be greatly appreciated!

Thanks

  • 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-12T16:40:21+00:00Added an answer on June 12, 2026 at 4:40 pm

    Please clarify your question if this isn’t what you are looking for.

    If you want an array of arrays of that Json data, you can do

    $decodedJsonData = array_map(
        function($jsonString) {
            return json_decode($jsonString, true);
        },
        file('/path/to/logfile')
    );
    

    This will read the entire file into an array line by line and apply json_decode to each line/element, resulting in an array of arrays of that Json data.

    For your Json above, the result would be (demo)

    Array
    (
        [0] => Array
            (
                [timestamp] => 2012-09-16 14:10:36
                [event] => log_start
                [unixTime] => 1347768636
            )
    
        [1] => Array
            (
                [timestamp] => 2012-09-16 14:10:36
                [event] => player_status
                [player] => Array
                    (
                        [name] => PLAYER NICKNAME
                        [userId] => 15
                        [uniqueId] => STEAM_X:X:XXXXXXX (STEAMID)
                        [team] => 1
                    )
    
                [address] => xxx.xxx.xxx.xxx (IP)
                [country] => AU
            )
        [2] => Array
            (
                [timestamp] => 2012-09-16 14:10:36
                [event] => live_on_3
                [map] => de_mirage_csgo
                [teams] => Array
                    (
                        [0] => Array
                            (
                                [name] => Terrorists
                                [team] => 2
                            )
    
                        [1] => Array
                            (
                                [name] => Counter-Terrorists
                                [team] => 3
                            )
    
                    )
                [status] => 5
                [version] => 1.0.0 Beta
            )
    )
    

    Further information:

    • file — Reads entire file into an array
    • array_map — Applies the callback to the elements of the given arrays
    • Chapter on callbacks
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently trying to communicate a parent process which should have multiple children
I'm currently trying to optimize the sluggish process of retrieving a page of log
I've been starting to learn hadoop, and currently I'm trying to process log files
I am currently trying to process a large block of simulation data (~2Gb worth).
I am currently trying to process a csv file in PHP using preg_match(). An
I'm currently trying to limit the memory resources of the process. Before to do
I have a relatively large C#/WPF Visual Studio 2008 solution that I am trying
I'm currently trying to build a code which is supposed to work on a
I'm currently trying to create a PHP Thrift server which will be accessed by
I am currently trying to import a list of executables from a text file

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.