【问题标题】:unable to create PHAR archive无法创建 PHAR 存档
【发布时间】:2014-04-21 13:50:37
【问题描述】:

我是 PHP 新手。 .

我已经尝试为我的项目制作一个 PHAR。

我的项目包括 5 个目录并在每个目录中增加类。

我已经学习了这个教程

Phar – PHP archiving practice

我做了以下事情:

在我的主要 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 就可以了)

【问题讨论】:

    标签: php phar


    【解决方案1】:

    使用 PHP2Phar 包从 PHP 文件创建 Phar 文件。

    链接: https://github.com/00F100/php2phar

    用法:

    $ php php2phar.phar --dir-source <path/to/dir> --index-file </path/to/index.php> --output-file <path/to/file.phar>  
    

    【讨论】:

    【解决方案2】:

    我不确定这是否是重点,但请查看此链接Bug #63112 PharException when compiling 可能你对临时目录有同样的问题吗?

    【讨论】:

    • 是的,我看到了这个,但我真的不知道如何处理他的回答:“我做过,但这是在 Parallels 下使用可扩展磁盘。我已经创建了一个固定磁盘并安装了它在 /tmp 上,现在编译成功完成。
    • @user2515512 他正在运行 mac os,所以 Parallels 有一些魔力 :) 你可以使用这篇文章来检查你的 PHP 如何与 tmp 目录进行交互sys_get_temp_dir
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-30
    • 1970-01-01
    • 2013-03-08
    • 2013-10-31
    • 2010-12-07
    • 1970-01-01
    相关资源
    最近更新 更多