php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #58722 confusion about using .tar.phar and the compressed version and the stub
Submitted: 2009-06-15 09:22 UTC Modified: 2014-02-01 10:07 UTC
From: carsten dot harnisch at intradesys dot com Assigned: krakjoe (profile)
Status: Closed Package: *General Issues
PHP Version: 5.3.0RC3 OS: linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: carsten dot harnisch at intradesys dot com
New email:
PHP Version: OS:

 

 [2009-06-15 09:22 UTC] carsten dot harnisch at intradesys dot com
Description:
------------
just checking out the version 2.0.0RC2 I am bit confused 
with the packing and compression functionality.

The basic use-case is to pickup the content of a directory 
and package it as a compressed phar.

To package I did :

$libBaseFile = 'include_this.php';
$pharAlias = 'mylib.tar.phar';
$pathToOutput = 'lib/';
$pathToLib = 'src/';

$phar = new Phar($pathToOutput, 0, $pharAlias);
$phar->buildFromIterator(
	new RecursiveIteratorIterator(
  	new RecursiveDirectoryIterator($pathToLib)), 
$pathToLib);

    
$phar->setStub(
'<?php '
// . 'echo "in stub<br>"; '
  . 'Phar::mapPhar("' . $pharAlias . '"); '
  . 'require_once "phar://" . __FILE__ . "/' . $libBaseFile 
.'"; '
  . '__HALT_COMPILER(); ?>'
  );
    
$phar->compress(Phar::GZ);

The first weird thing I encountered is that if I called the 
"$pharAlias" as "mylib.tar.phar" the resulting compressed 
version will be "mylib.phar.tar.gz".
Not really sure if this is the attend way, so managling the 
extension "tar.phar".

The next thing is that I would assume "including" the phar 
later should run the stub. But in fact this is only the case 
for the "uncompressed" version :

// this will work and "include" libBaseFile and defined in 
the stub !
require_once 'phar://lib/mylib.tar.phar';

// this seems NOT running the stub ...
require_once 'phar://lib/mylib.phar.tar.gz';

// ... but this will work ...
require_once 
'phar://lib/mylib.phar.tar.gz/include_this.php';

I am open to commit changes to the docs once the issue is 
solved.

best wishes

Carsten


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-06-15 09:33 UTC] greg at chiaraquartet dot net
Hi Carsten,

To have control over the extension, use Phar::convertToExecutable() or Phar::convertToData().  Feel free to add a note to the compress() documentation.

Greg
 [2009-06-15 10:33 UTC] carsten dot harnisch at intradesys dot com
Greg,
thanks for your help ...

Just digging into the issue again. I found that the 
"problem" seems to be 
related to the way compress is working  in relation to any 
"custom" stubs 
:

This code here will produce the compressed phar (my.phar.gz)

$phar = new Phar('my.phar', 0, 'my.phar');
$phar->setDefaultStub('other_than_index.php', 
'other_than_index.php');
$phar->compress(Phar::GZ);

so "compress" seems to ignore any custom-stubs; the 
resulting archive has 
always a "default-stub" with "index.php" inside. I assume 
that 
convertToExecutable works pretty much the same ?!?
Not really sure if this is intended here, might be nicer to  
allow custom-
stubs in a .gz also.
 [2014-02-01 10:07 UTC] krakjoe@php.net
-Status: Open +Status: Closed -Package: phar +Package: *General Issues -Assigned To: +Assigned To: krakjoe
 [2014-02-01 10:07 UTC] krakjoe@php.net
This bug is reported for an unsupported version of PHP and is not connected to security.

It is therefore being closed.

If the bug is still present in a stable, supported version of PHP, please do open a new bug report.

Thanks for taking the time to help make PHP better :)
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Sat Oct 10 07:00:01 2026 UTC