【发布时间】:2014-04-21 13:50:37
【问题描述】:
我是 PHP 新手。 .
我已经尝试为我的项目制作一个 PHAR。
我的项目包括 5 个目录并在每个目录中增加类。
我已经学习了这个教程
我做了以下事情:
在我的主要 index.php 中,我添加了以下几行:
$sLibraryPath = 'lib/myPhar.phar';
// we will build library in case if it not exist
if (! file_exists($sLibraryPath)) {
ini_set("phar.readonly", 0); // Could be done in php.ini
$oPhar = new Phar($sLibraryPath); // creating new Phar
$oPhar->setDefaultStub('index.php', 'classes/index.php'); // pointing main file which require all classes
$oPhar->buildFromDirectory('classes/'); // creating our library using whole directory
$oPhar->compress(Phar::GZ); // plus - compressing it into gzip
}
我创建了一个名为 classes 的新文件夹,并在其中创建了一个 index.php 文件,其中包含了我所有的项目类。
我有 chmod 777 以下目录:lib、HelloWorld、HelloWorld/index.php,
并更改了 phar.readonly。 (phar.readonly = 0)
我仍然收到这条消息:
Fatal error: Uncaught exception 'PharException' with message 'unable to create temporary file' in /Applications/XAMPP/xamppfiles/htdocs/HelloWorld/index.php:10 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/HelloWorld/index.php(10): Phar->setDefaultStub('index.php', 'classes/index.p...') #1 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/HelloWorld/index.php on line 10
我还没有找到任何有用的信息如何处理它,我很乐意为您提供帮助。
(如果有更好的方法来创建 PHAR 就可以了)
【问题讨论】: