Solved

How would I decompress and parse 365 JSON files, each over a gig?

Posted on 2014-09-25
6
84 Views
Last Modified: 2014-09-26
I've got the script I need to decompress and parse the files, but what I need now is something that can "look" into the directory and automatically grab each file, process it and then move on to the next.

I can't imagine how I could do that, unless I had the name of each file loaded in a database somewhere.

Perhaps some clever spin on fopen?

How could I do it so I could initiate the process as I'm headed out the door and the process continue automatically through the nite and be done in the morning?
0
Comment
Question by:brucegust
6 Comments
 
LVL 9

Assisted Solution

by:Brian Tao
Brian Tao earned 125 total points
ID: 40345391
This skeleton may be what you need:
if ($dh = opendir("$dir_name")){
  while (($file = readdir($dh)) !== false){
    // code for processing each individual file
    // e.g. print the file name
    echo "$file <br>\n";
  }
  closedir($dh);
}

Open in new window

0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 40345909
Here is what I would do.

Get a list of the files.  Scandir() will handle that part.  Then with each file name, start a process to do whatever you want with the file.  You can use fsockopen() or cURL to start the process.  Give the process script the name of the file and let it run.  You will want to start the process with a POST-method request, so you can disconnect and let the process run asynchronously.

You probably want to sleep() a few moments between starting the processes.  You probably want to keep a log of the file names and a timestamp when the process was started.  You probably want to keep a log of the times when each process ended, so you know what succeeded and what failed.
0
 

Author Comment

by:brucegust
ID: 40346075
Gentlemen!

Thanks so much for your willingness to share your expertise!

Question: In both your examples, the output includes two rows of "blank" values. By that I mean, in my current directory, I have one file. Rather than that file being listed by itself, with taoyipai' s suggestion I get:

.
 ..
 00_8ptcd6jgjn201311060000_day.json

Ray, with your scenario I get:

Array ( [0] => . [1] => .. [2] => 00_8ptcd6jgjn201311060000_day.json ) Array ( [0] => 00_8ptcd6jgjn201311060000_day.json [1] => .. [2] => . )

Again, you're getting those "dots" and I'm wondering, first of all, what they represent and, secondly, how can I remove them from the list of files that I want to preform some code on? In other words, how do I ensure that the list of files in the directory do not include "." and ".."?
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 10

Assisted Solution

by:Chris_Gralike
Chris_Gralike earned 125 total points
ID: 40346142
This will remove the dots from the array.

$d = scandir($path);

foreach($d as $k => $v){
        if( !(( $v === '.') || ($v === '..')) ){
                $files[]= $v";
        }
}

print_r($files);

Open in new window

0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 250 total points
ID: 40346153
getting those "dots" and I'm wondering, first of all, what they represent
They are directory indicators and irrelevant to your application.  You would only be looking for files that end in ".json" right?  Skip the others as you process the array.
0
 

Author Comment

by:brucegust
ID: 40346172
Got it!

Thank you!

Also, feel free to head out to http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/Q_28526319.html for a question that pertains to the next piece of scaffolding for this project...
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now