Skip to Main Content
PHP 5 Kochbuch, Third Edition
book

PHP 5 Kochbuch, Third Edition

by David Sklar, Adam Trachtenberg, Carsten Lucke, Matthias Brusdeylins, Ulrich Speidel, Stephan Schmidt
September 2009
Intermediate to advanced content levelIntermediate to advanced
912 pages
48h 11m
German
O'Reilly Verlag
Content preview from PHP 5 Kochbuch, Third Edition

24.10 Ein PHP-Archiv (PHAR) erstellen

Problem

Sie wollen ein PHP-Archiv erstellen, das Ihre Anwendung, Ihr Framework oder Ihre Bibliothek enthält. Sie möchten das Archiv so weitergeben, dass der Anwender es direkt einbinden oder ausführen kann, ohne die Inhalte vorher zu entpacken.

Lösung

Schreiben Sie das Programm, das Sie weitergeben wollen, beispielsweise eine Datei mit dem Namen index.php und dem folgenden Inhalt:

<?php
    echo "Hallo, ich bin in einem PHP-Archiv!";
?>

Dann schreiben Sie ein kleines Installationsprogramm, das für Sie das obige Skript in ein PHP-Archiv packt:

<?php
    $phar = new Phar('beispiel1.phar');
    $phar->setStub($phar->createDefaultStub('index.php'));
    $phar->addFile('index.php');
?>

Diskussion

PHAR ist das Kürzel für »PHP Archive«. ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PHP programmieren unter Windows

PHP programmieren unter Windows

Arno Hollosi
CSS Kochbuch, 3rd Edition

CSS Kochbuch, 3rd Edition

Joergen Lang, Christopher Schmitt

Publisher Resources

ISBN: 9783868993271Purchase book