5

I know how to convert php file into phar file.

$phar = new PHAR('app.phar');
$phar->addFile('file1.php');
$phar->addFile('file2.php');

I thought it can be useful only for converting POPO to PHAR.

My question

Is it possible to convert entire Zend framework 2 web application to PHAR file? if yes, then How?

(or)

How to package Zend framework2 web application into a package? (except .zpk(zend studio package file) file format)


Updated: creating Phar from entire application

create-phar.php

$basePath = /path/to/;
$path = /path/to/application;  
$phar = new Phar ('project.phar');    
$phar->buildFromIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)), $basePath);
$phar->setStub("<?php 
    Phar::webPhar('project', 'public/index.php');
       include 'phar://project/public/index.php';
       __HALT_COMPILER();
    ?>");

index.php

<?php
include 'project.phar';
?>

Question:

When i run index.php it do not redirect to actual public/index.php file instead it shows blank page on the browser. How can I resolve this problem?

Thanks in advance

codeninja.sj
  • 3,452
  • 1
  • 20
  • 37
  • Take a look [here](http://stackoverflow.com/questions/15750913/generating-a-phar-for-a-simple-application) . Also IMHO packing whole app is not a good idea. Fist, in times of composer it will be harder to develop, and second - as far as I know `APC` doesn't support `phar`, so you will hit great performance bottleneck. – ex3v Jul 22 '14 at 08:57
  • I like your question, this will be useful for developers that want to hide its code in order to deliver it to companies. – peterpeterson Jul 22 '14 at 10:03
  • 1
    @BrunoQuintanaFleitas [Not really](http://php.net//manual/pl/phar.extractto.php) – ex3v Jul 22 '14 at 11:07

1 Answers1

6

I deploy phorkie as a .phar file.

There are some things to consider:

  1. Pack up all files in the .phar - php and static asset files (js, css, png, jpg), too. I use phing to do that. Do not forget the dependencies.
  2. You need a stub file that runs Phar::webPhar() which takes care of sending out HTTP headers
  3. Write your own .htaccess rewrite rule interpreter, because Phar::webPhar() does not do nice-path resolving on its own. I did that already.
  4. Manually take care of sending out caching headers for static files
  5. Hope that you (or your users) don't run into one of the Phar::webPhar bugs:
    1. Symlinked files
    2. No HEAD, PUT or DELETE support
    3. Redirection loop with FPM (already fixed in git)
  6. Hope that your user's web server handles .phar files (it will not; neither Debian nor Fedora ship that configuration)
  7. Hope that the user's web server is correctly configured to handle .phar files with PATH_INFO appended (/path/to/file.phar/foo/bar.png), like in http://p.cweiske.de/122

Getting phorkie running from the .phar took me the evenings of two weeks. Now that it basically works it still is not a drop-phar-and-play solution, because the default configuration of web servers just doesn't play nice with .phar.

Christopher K.
  • 1,015
  • 12
  • 18
cweiske
  • 30,033
  • 14
  • 133
  • 194