Question

Can anyone give me some pointers with regard PHP command execution and best practice?

Im currently trying to parse some netbackup data, but i am running into issues related to the massive amount of data the system call is returning. In order to cut down the amount of data im retreiving I'm doing something like this:

$awk_command = "awk -F, '{print $1\",\"$2\",\"$3\",\"$4\",\"$5\",\"$6\",\"$7\",\"$9\",\"$11\",\"$26\",\"$32\",\"$33\",\"$34\",\"$35\",\"$36\",\"$37\",\"$38\",\"$39\",\"$40}'";
exec("sudo /usr/openv/netbackup/bin/admincmd/bpdbjobs -report -M $master_name -all_columns | $awk_command", $get_backups, $null);
foreach ($get_backups as $backup_detail)
    {
    process_the_data();
    write_data_to_db();
    }

Im using awk to limit the amount of data be received. Without it i end up receiving nearly ~150mb of data, and with it, i get a much more manageable ~800k of data.

You don't need to tell me that the awk shit is nasty - i know that already... But in the interests of bettering myself (and my code) can anyone suggest an alternative?

I was thinking of something like proc_open but really not sure if that is going to provide any benefits.

Was it helpful?

Solution

Use exec to write the data to a file instead of reading it whole into your script.

exec("sudo /usr/openv/netbackup/bin/admincmd/bpdbjobs -report -M $master_name -all_columns | $awk_command > /tmp/output.data");

Then use any memory efficient method to read the file in parts.

Have a look here: Least memory intensive way to read a file in PHP

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top