Phar/setup-Phpdoc专题
安装/配置
目录
需求
Phar requires PHP 5.2.0 or newer. Additional features require the SPL extension in order to take advantage of iteration and array access to a Phar's file contents. The phar stream does not require any additional extensions to function.
You may optionally wish to enable the zlib and bzip2 extensions to take advantage of compressed phar support. In addition, to take advantage of OpenSSL signing, the OpenSSL extension must be enabled.
Note that a bug in the zlib.deflate stream filter fixed in PHP version 5.2.6 and newer may cause truncation of gzip and bzip2-compressed phar archives.
PHP 5.3 configured with --enable-zend-multibyte makes phar dependant on the ini option detect_unicode.
安装
自 PHP 版本 5.3.0 Phar 扩展成为了内置的组件。在之前的版本,Phar 可以通过 PECL 扩展安装 » Phar PECL 页面 包含了历史以及更多信息。
运行时配置
这些函数的行为受 php.ini 中的设置影响。
| 名字 | 默认 | 可修改范围 | 更新日志 |
|---|---|---|---|
| phar.readonly | "1" | PHP_INI_ALL | |
| phar.require_hash | "1" | PHP_INI_ALL | |
| phar.cache_list | "" | PHP_INI_SYSTEM |
这是配置指令的简短说明。
phar.readonly bool
This option disables creation or modification of Phar archives using the
phar stream or Phar object's write
support. This setting should always be enabled on production machines,
as the phar extension's convenient write support could allow
straightforward creation of a php-based virus when coupled with other
common security vulnerabilities.
Note:
This setting can only be unset in php.ini due to security reasons. If phar.readonly is disabled in php.ini, the user may enable phar.readonly in a script or disable it later. If phar.readonly is enabled in php.ini, a script may harmlessly "re-enable" the INI variable, but may not disable it.
phar.require_hash bool
This option will force all opened Phar archives to contain some kind of
signature (currently MD5, SHA1, SHA256, SHA512 and OpenSSL are
supported), and will refuse to process any Phar archive that does not
contain a signature.
Note:
This setting can only be unset in php.ini. If phar.require_hash is disabled in php.ini, the user may enable phar.require_hash in a script or disable it later. If phar.require_hash is enabled in php.ini, a script may harmlessly "re-enable" the INI variable, but may not disable it.
This setting does not affect reading plain tar files with the <span class="classname">PharData class.
Caution phar.require_hash does not provide any security per se, it is merely a measure against running accidentially corrupted Phar archives, because anyone who would be able to tamper with the Phar could easily fix the signature afterwards.
phar.cache_list string
Allows mapping phar archives to be pre-parsed at web server startup,
providing a performance improvement that brings running files out of a
phar archive very close to the speed of running those files from a
traditional disk-based installation.
示例 #1 phar.cache_list usage example
in php.ini (windows):
phar.cache_list =C:\path\to\phar1.phar;C:\path\to\phar2.phar
in php.ini (unix):
phar.cache_list =/path/to/phar1.phar:/path/to/phar2.phar
资源类型
The Phar extension provides the phar stream, which allows accessing files contained within a phar transparently. See also the description of the Phar file format.