سؤال

I need to perform some tar gzip operation inside a php script running on Apache (php5.3).

In the past, I've used:

new PharData($archivePath . '.tar');
$p = $p->convertToExecutable(Phar::TAR, Phar::GZ);
$p->startBuffering();

However in this case it could have to handle 1GB+ files. So I'm worried about overloading php/apache.

In that case, is it best to rely on shell_exec & let the os take the load?

هل كانت مفيدة؟

المحلول

I agree with Marc B, the major considerations I would think of are:

Deployment Environment... Using Shell ties you to an environment where shell commands can run, and tar is accessible. Using Phar is nice because if the extension is installed, you should be good to go. With shell you're now tied to linux as well, unless you put the logic in to work in windows as well.

Also, security issues... While it is definitely possible to run shell commands from php without introducing vulnerabilities, it does provide a way now for malicious people to run a command if you accidently don't scrub the data good enough. Also, tar will die if you run out of space with who knows what, whereas if you use Phar, you should get a reasonable error message from php indicating the problem, instead of just a bad return code.

One advantage of shell, is that if you run the command asynchronously and get a stream from stdout you can monitor progress, sort of.

Either way, half a dozen of one, 6 of the other...

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top