我是一个PHP新手。。
我试着让我的项目变得更好。
我的项目包括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文件,其中包含了我所有的项目类。
我已经修改了以下目录: 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,那就好了)
发布于 2014-03-16 19:59:08
我不确定这是否是重点,但检查这个链接Bug #63112 PharException when compiling可能你有同样的问题与临时目录?
发布于 2016-10-04 01:26:22
使用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> https://stackoverflow.com/questions/22436045
复制相似问题