5
Voglio avviare uno script phar come eseguibile, direttamente eseguendo foo.phar <params>
anziché php foo.phar <params>
.Come creare un file eseguibile?
Voglio avviare uno script phar come eseguibile, direttamente eseguendo foo.phar <params>
anziché php foo.phar <params>
.Come creare un file eseguibile?
È facile modificando lo stub predefinito (aggiungendo lo shebang corrispondente a php).
// start buffering. Mandatory to modify stub.
$phar->startBuffering();
// Get the default stub. You can create your own if you have specific needs
$defaultStub = $phar->createDefaultStub('index.php');
// Adding files
$phar->buildFromDirectory(__DIR__, '/\.php$/');
// Create a custom stub to add the shebang
$stub = "#!/usr/bin/php \n".$defaultStub;
// Add the stub
$phar->setStub($stub);
$phar->stopBuffering();
Dal momento che l'eseguibile di PHP non è in '/ usr/bin/php' su tutti i sistemi, è meglio usare' #!/Usr/bin/env php' invece. Vedere http://tech.vg.no/2012/02/21/dont-hardcode-php-executable-path-in-shebang/ – chiborg
Per qualche motivo non funzionava sul mio server Ubuntu 10.04 LTS ... – magnetik
Questo metodo funziona su Windows? – weynhamz