Creazione di un file PHP Phar

Crea il file: src/index.php

<?php 
// Filename: src/index.php
// Optional load composer autoloader
//require_once __DIR__ . '/vendor/autoload.php';
echo "App started";

Crea il file: create-phar.php

<?php
// The php.ini setting phar.readonly must be set to 0
$pharFile = 'app.phar';

// clean up
if (file_exists($pharFile)) {
    unlink($pharFile);
}
if (file_exists($pharFile . '.gz')) {
    unlink($pharFile . '.gz');
}

// create phar
$p = new Phar($pharFile);

// creating our library using whole directory  
$p->buildFromDirectory('src/');

// pointing main file which requires all classes  
$p->setDefaultStub('index.php', '/index.php');

// plus - compressing it into gzip  
$p->compress(Phar::GZ);
   
echo "$pharFile successfully created";

utilizzo

php create-phar.php

Avviare il file phar

php app.phar

Related Posts

Leave a comment

Hey, so you decided to leave a comment! That's great. Just fill in the required fields and hit submit. Note that your comment will need to be reviewed before its published.