Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unexpected problems with PHP PHAR

Tags:

php

glob

phar

After a little testing/scripting/playing with PHP 5.3 PHAR archives, I discovered some problems.

glob

PHAR doesn't work with glob. Neither as wrapper (http://www.php.net/manual/en/phar.using.stream.php#104320) nor as a function call.

In my test project I had to iterate over the files in the PHAR and filter the result by a glob-equivalent regular expression.

imagettfbbox

I have no idea why, but imagettfbbox also doesn't understand the PHAR stream wrapper.

The easiest solution here, was to extract the file via copy(). (PHAR::extractTo return with an exception without a stacktrace nor a line number.)

Are there other surprises, which I should expect? Are there other known issues? And are they documented anywhere?

like image 484
mheinzerling Avatar asked Nov 20 '11 17:11

mheinzerling


2 Answers

The silex microframework is distributed as a phar file. We have documented most of the issues we ran into in the pitfalls section of the documentation (archived copy).

Note: This is mostly from a user perspective.

like image 194
igorw Avatar answered Oct 21 '22 14:10

igorw


glob: I don't think that glob supports streams, so this won't be specific to phar:// but any stream wrapper.

imagettfbbox: I think this is the same, no support for stream wrappers, but only bare files.

There are other functions, you encounter the same, too. For example the ZIP class can't handle streams as well.

And not all stream wrapper support stream wrapper stacking, e.g. one wrapper operating on another.

Feel free to open feature requests in the php bugtracker and/or support the PHP development to introduce better stream support for the components you need it for.

Loosely related: In memory download and extract zip archive

like image 2
hakre Avatar answered Oct 21 '22 15:10

hakre