Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Static content inside phar archive

Tags:

php

phar

I was just wondering if it is legal to add static content to phar archives (images, javascript or html files). And if so, how do I get them out to serve to a client?

The only example I've seen so far was:

<?php
header('Content-type: image/jpeg');
echo file_get_contents('phar:///fullpath/to/coollibrary.phar/images/wow.jpg');
?>

but I guess this is not a way to go.

UPATE: Just in case someone will be trying to do the same. This piece of code set as a stub of a phar archive worked for me:

<?php
    Phar::interceptFileFuncs();
    Phar::mungServer(array('REQUEST_URI'));
    Phar::webPhar();
    __HALT_COMPILER();
?>

All static content inside the phar archive still passes through the php interpreter, but at least there is no need do stuff like setting header mime type and serving the static file content with readfile() manually. Those functions in the phar stub make it look transparent.

like image 423
facha Avatar asked Jul 21 '11 21:07

facha


1 Answers

but I guess this is not a way to go.

Because the only thing that can look inside phars is PHP, having PHP extract the contents and echo the result is pretty much the only way to go.

You might find the PHP manual page on the PHAR extension to be useful, and the webPhar method to be particularly enlightening. interceptFileFuncs could also be handy.

like image 124
Charles Avatar answered Sep 23 '22 16:09

Charles