dosryjij88555
2015-05-11 18:19
浏览 41
已采纳

错误将整个Slim应用程序打包到Phar文件中

I have a Slim Application with the following directory structure:

app/
vendor/
www/

config.php

In app/ I have the relevant files of the project, in vendor/ the dependencies managed by composer and in www/ the files accesible by the web server.

So I am thinking to create a Phar file along the lines of:

<?php

$full_path = '/home/.../forms/';
$package_name = 'www/package.phar';

try {
    $phar = new Phar($full_path . $package_name, 
    FilesystemIterator::CURRENT_AS_FILEINFO |       FilesystemIterator::KEY_AS_FILENAME, $full_path . $package_name);

$phar->startBuffering();

$phar->addFile($full_path . 'www/index.php');
$phar->addFile($full_path . 'www/bootstrap.php');
$phar->addFile($full_path . 'www/session_start.php');


// Grab config
$phar->addFile($full_path . 'config.php');


$phar->buildFromIterator(new RecursiveIteratorIterator (new RecursiveDirectoryIterator('../app', FilesystemIterator::SKIP_DOTS)),'../app');
$phar->buildFromIterator(new RecursiveIteratorIterator (new RecursiveDirectoryIterator('../vendor', FilesystemIterator::SKIP_DOTS)),'../vendor');

$phar->setDefaultStub('bootstrap.php', 'bootstrap.php');

$phar->stopBuffering();

echo "Phar created.";

} catch (Exception $e) {
// handle errors here
echo $e->getMessage();
}

So I create that way the phar and then I have:

deploy.php

<?php

require_once 'phar://package.phar/bootstrap.php';
$app->run();

But when accesing /deploy.php I am getting:

[Fri May 15 20:07:02 2015] [error] [client 10.0.2.2] PHP Warning: require_once(phar://package.phar/bootstrap.php) [function.require-once]: failed to open stream: Cannot open archive "/vagrant/www/package.phar", invalid alias in /vagrant/www/deploy.php on line 3 [Fri May 15 20:07:02 2015] [error] [client 10.0.2.2] PHP Fatal error: require_once() [function.require]: Failed opening required 'phar://package.phar/bootstrap.php' (include_path='.:/usr/share/php:/usr/share/pear') in /vagrant/www/deploy.php on line 3

Do you think I should be addressing it like this?

Thanks

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • douwei1950 2015-05-18 08:44
    最佳回答

    EDIT:

    "Creating the phar in a shared folder of a Vagrant box caused that problem. Once I changed "output" property to a location outside the shared folder the error went away." source


    You should check your php.ini: phar.require_hash = Off

    Or sign your Phar with setSignatureAlgorithm()

    Or with Phing: <pharpackage ... signature="sha512"> ...

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题