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"> ...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 这个复选框什么作用?
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决