Creation of multiple zip files

Asked

Viewed 21 times

0

I’m having a problem in PHP/Laravel to create multiple zip files synchronously, I copy all commands that are generated and run in Shell, it performs beauty, but when step to PHP run only generates the first file.

Controller Code.

foreach ($passwords as $p){
            if($i == 0){
                $command = 'zip -u -j -P '.$p.' '.$dir.'/'.$count.'.zip '.storage_path().'/app/'.$directory.'/'.$file1->getClientOriginalName();
                $commands->push($command);
            }else{
                $command = 'zip --quiet -j -P '.$p.' '.$dir.'/'.$count.'.zip '.storage_path().'/app/'.$directory.'/'.($count+1).'.zip';
                $commands->push($command);
            }
            $count--;
            $i++;
        }
        foreach ($commands as $p){
            echo $p.'<br/>';
        }
        foreach ($commands as $c){
            $process = new Process($c);
            $process->start();
            sleep(10);
            if($process->isTerminated()){
                sleep(1);
            }
            if ($errorOutput = $process->getErrorOutput()) {
                throw new RuntimeException('Process: ' . $errorOutput);
            }
        }

Code generated in Collect $Commands.

Script only generates 50.zip file, does not continue forward.

  • How are you instantiating variable $commands? Which object is it instantiated? Why not use it as array, for example $commands[] = "comando"; ?

  • It is an Laravel Collect, as if it were an array. The data is in memory, the problem is when it will run in $process ai gives problem. It says the file was not found, but it is there.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.