There was an error in this gadget

Saturday, April 9, 2011

If your Phar doesn't work well ...

Do you know Phar extension? Here is a introduction in PHP official manual below:
What is phar? Phar archives are best characterized as a convenient way to group several files into a single file. As such, a phar archive provides a way to distribute a complete PHP application in a single file and run it from that file without the need to extract it to disk. Additionally, phar archives can be executed by PHP as easily as any other file, both on the commandline and from a web server. Phar is kind of like a thumb drive for PHP applications. (via.

Phar requires PHP 5.2.0 or newer. If your PHP is PHP 5.3, the Phar extension is build into PHP in default, otherwise Phar may be installed via the PECL extension with previous PHP versions.
If your Phar doesn't work well after you installed; the error has occured and so on, you have to check your php configure below.

check configure options

If you installed or compiled php with "--enable-zend-multibyte" option, Phar doesn't work well. So you have to recompile your php without "--enable-zend-multibyte".
For example, you installed php with brew, you have to modify your file.

Launch your text editor, and comment out the "--enable-zend-multivyte" line and save it.

    $ brew edit php

#      "--enable-zend-multibyte",

Suhosin Phar "URL not allowed"

If you use Suhosin PHP, Phar doesn't work well becase of its high security setting. So you have to check here.
In addition, Kagaya Masaki mailed me how to modify the php.ini for the environment of Suhosin PHP.
You may have to check your php.ini and modify it:

    detect_unicode = Off
    suhosin.executor.include.whitelist = phar


I hope these tips will help you :)

1 comment: