composer.phar
phing.phar
drush.phar
phpunit.phar
php coolapplication.phar<?php
include 'coollibrary.phar';
?><?php
include 'phar://coollibrary.phar/internal/file.php';
header('Content-type: image/jpeg');
// phars can be accessed by full path or by alias
echo file_get_contents('phar:///fullpath/to/coollibrary.phar/images/wow.jpg');
?><?php
// create with alias "project.phar"
$phar = new Phar('project.phar', 0, 'project.phar');
$phar->buildFromIterator(
new ArrayIterator(
array(
'internal/file.php' => dirname(__FILE__) . '/somefile.php',
'another/file.jpg' => fopen('/path/to/bigfile.jpg', 'rb'),
)));
$phar->setStub($phar->createDefaultStub('cli/index.php', 'www/index.php'));
?><?php
// create with alias "project.phar"
$phar = new Phar('project.phar', 0, 'project.phar');
// add all files in the project
$phar->buildFromDirectory(dirname(__FILE__) . '/project');
$phar->setStub($phar->createDefaultStub('cli/index.php', 'www/index.php'));
?><?php
$phar2 = new Phar('project2.phar', 0, 'project2.phar');
// add all files in the project, only include php files
$phar2->buildFromDirectory(dirname(__FILE__) . '/project', '/\.php$/');
$phar2->setStub($phar->createDefaultStub('cli/index.php', 'www/index.php'));
?><?php
try {
$phar = new Phar('myphar.phar');
$phar->setStub($phar->createDefaultStub('cli.php', 'web/index.php'));
} catch (Exception $e) {
// handle errors
}
?>php composer.phar create-project slim/slim-skeleton project
<?php
// create with alias "project.phar"
$phar = new Phar('project.phar', 0, 'project.phar');
// add all files in the project
$phar->buildFromDirectory(dirname(__FILE__) . '/project');
$phar->setStub($phar->createDefaultStub('public/index.php'));
?>php -d phar.readonly=0 compiler.php
php -S localhost:8080 project.phar
PHP 7.3.8 Development Server started at Fri Aug 23 01:11:18 2019
Listening on http://localhost:8080
Document root is /Users/iche/projects/MY/test
Press Ctrl-C to quit.php -S localhost:8080 project.pharPhar::createDefaultStub
<?php
// creating the phar archive:
try {
$phar = new Phar('myphar.phar');
$phar['index.php'] = '<?php echo "Hello World"; ?>';
$phar->setStub('<?php
Phar::mungServer(array(\'REQUEST_URI\'));
Phar::webPhar();
__HALT_COMPILER(); ?>');
} catch (Exception $e) {
// handle error here
}
// GET /myphar.phar/index.php
?>// Create new file
$phar->compress(Phar::GZ,'.phar.gz'); // file.phar.gz
if (Phar::canCompress(Phar::GZ))
{
$phar->compress(Phar::GZ,'.phar.gz');
}
// Compress files in archive
$phar->compressFiles(Phar::GZ); // same name
if (Phar::canCompress(Phar::GZ))
{
$phar->compressFiles(Phar::GZ);
}
/**
* Phar::MD5
* Phar::SHA1
* Phar::SHA256
* Phar::SHA512
* Phar::OPENSSL
*/
$signatures=Phar::getSupportedSignatures();
if (in_array(PHAR::SHA512,$signatures))
{
$phar->setSignatureAlgorithm(PHAR::SHA512);
}