Reputation: 11
I'm using gzip with PHP to zip up some log files. My development machine is windows, and as you all know, a windows the path are sometimes separated by a space which makes it difficult because I have to wrap everything in quotes to get to the logs.
I'd like to keep my code as clean as I can and was wondering if there is a compression utility that will take the same file to be compressed and zip that file instead of creating a new, compressed file. This way, I wouldn't have to run a separate command to delete the uncompressed file afterwards.
Just for clarification, I'm not using shell_exec to zip these, but instead, PHPs internal functions. "gzwrite" etc.
Upvotes: 1
Views: 137
Reputation: 276
zip that file 99,99999% of the time means just this:
that file
, compress it and write to that file.zip
that file
.That's what winzip does. That's what gzip does. Why would you want different? to save one line of code?
I hope you realize, that overwriting any bit of the file before the compression finished with success, is plain wrong.
Upvotes: 0
Reputation: 558
If the log files are not larger than the allocated php memory you could read in the whole log file then use gzcompress/gzencode to compress the file in memory then write the data back out to the file. You might then need to rename the file to append .gz to the end. Hopefully this helps.
Upvotes: 1
Reputation: 19171
If windows, why not create a little utility that does that for you? It could just be two lines ... perform the gzip then rename the file to the original.
BTW - doesn't gzip by default delete the original after creating original_file.gz?
Upvotes: 0