©
Dokumen ini menggunakan Manual laman web PHP Cina Lepaskan
The Phar stream wrapper fully supports fopen() for read and write (not append), unlink() , stat() , fstat() , fseek() , rename() and directory stream operations opendir() and as of version 2.0.0, rmdir() and mkdir() .
Individual file compression and per-file metadata can also be manipulated in a Phar archive using stream contexts:
<?php
$context = stream_context_create (array( 'phar' =>
array( 'compress' => Phar :: GZ )),
array( 'metadata' => array( 'user' => 'cellog' )));
file_put_contents ( 'phar://my.phar/somefile.php' , 0 , $context );
?>
The phar stream wrapper does not operate on remote files, and cannot operate on remote files, and so is allowed even when the allow_url_fopen and allow_url_include INI options are disabled.
Although it is possible to create phar archives from scratch just using stream operations, it is best to use the functionality built into the Phar class. The stream wrapper is best used for read-only operations.
[#1] staff at pro-unreal dot de [2011-06-08 22:52:04]
Please note that the phar stream wrapper does not work with any glob.
When you decide to move your project to phar archives you need to consider this.
The following won't work:
<?php
glob('phar://some.phar
$dirname
)$file
[, string $localname
] )$localname
, string $contents
)$base_dir
[, string $regex
] )$iter
[, string $base_directory
] )$type
= 0
] )$compression
[, string $extension
] )$compression
)$fname
[, int $flags
[, string $alias
]] )$format
= 9021976
[, int $compression
= 9021976
[, string $extension
]]] )$format
= 9021976
[, int $compression
= 9021976
[, string $extension
]]] )$oldfile
, string $newfile
)$indexfile
[, string $webindexfile
]] )$extension
] )$entry
)$pathto
[, string|array $files
[, bool $overwrite
= false
]] )$format
)$filename
[, bool $executable
= true
] )$filename
[, string $alias
] )$alias
[, int $dataoffset
= 0
]] )$pharpath
, string $externalpath
)$munglist
)$offset
)$offset
)$offset
, string $value
)$offset
)$retphar
= true
] )$alias
)$index
[, string $webindex
]] )$metadata
)$sigtype
[, string $privatekey
] )$stub
[, int $len
= -1
] )$archive
)$alias
[, string $index
= "index.php"
[, string $f404
[, array $mimetypes
[, callable $rewrites
]]]]] )[#1] cornelius dot howl at gmail dot com [2011-12-19 00:49:57]
Onion utility can help you compile a package into a phar file (executable script file or library file)
https://github.com/c9s/Onion
$ onion.phar compile \
--executable \
--classloader \
--bootstrap scripts/onion.embed \
--lib src \
--lib ../CLIFramework/src \
--lib ../GetOptionKit/src \
--output onion.phar
[#2] halfdan [2008-05-17 13:18:36]
Hey, I thought writing a small article about the upcoming functionality and appearance of Phar in php5.3 might be a nice thing. So I did this at http://geekmonkey.org/articles/PHP_Archives - hope to save others some time when working with Phar.