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 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记