0

I have a PHP script which provides some output to angular. That script is useful to get the informations from the Perl script. I'm using exec() command to call the scripts in PHP. I'm getting what I want, but the problem is time-consuming. I executing the same script thrice to create the array in php. e.g:

exec("/usr/bin/reports -h -r -t ".$this->name." | grep -o '^\S*' | sed '1 d'",$report_id);
exec("/usr/bin/reports -h -r -t ".$this->name." | grep -oP '(?<= ).*' | sed '1 d'",$titles);
exec("/usr/bin/reports -h -r -n ".$this->name." | grep -oP '(?<= ).*' | sed '1 d'",$fullnames); 

As you can see I'm executing the same script multiple times only because of changing parameters.

By first command I'm storing report_id, the second command to store their position and third is for their full names. I need a solution to comprise these three commands into one. Please help to avoid the time complexity.

AdminBee
  • 22,803
Aroon
  • 101

1 Answers1

0
  1. I suggest to use AWK, it can parse multiple regexs and separates the fields automatically. It easy and small language available in all Unix, created especially for such jobs.
  2. A better way is to get the output and do your processing with the PHP. exec() returns the output in array of lines. preg_split() can do the grep/sed/cut job.
  3. You can use the tee command to use the output of reports in multiple pipes.
  4. Finally, you can use a customized lock mechanism, but I do not suggest it.