user1611597 user1611597 - 28 days ago 10
PHP Question

PharData open a large archive

I want to open in php a tar file of 45GB and about 5 millions files. I don't want to extract it. I just want to get the content of a single file(something about 10kb).

So far I have tried :

new PharData('tar file');


and

file_get_contents('phar://file.tar/single file');


I get this error:


Fatal error: Allowed memory size of 268435456 bytes exhausted


Is there a way to get the content of a single file from a large archive without reading the whole archive. Or something that takes less memory?

tar -xvf {tarball.tar} {path/to/file} is disabled by my host

Thanks

I found some answers where people were saying that this can not be done with tar. For tar you need to read the whole content in order to extract a single file.

My question is now, what format can you use in order to read a single file from a large archive without loading the entire archive.

Thank you

Answer Source

For tar you need to read the whole content in order to extract a single file

Not true. But compression adds complications when working with CLI tools. IIRC, the PEAR tar package can extract single files from gzipped tar archives without reading the whole file into memory.

Why do you need a 45Gb archive? Is it for deployment? If not then you really need to think about a different way of storing your data or switch providers.