Solved

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

Posted on 2014-09-25
6
93 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 110

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

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 110

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

728 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