• Increase font size
  • Default font size
  • Decrease font size
Home Software PHK PHK FAQ

PHK FAQ

E-mail Print
Read : 5,251 times
(0 votes, average 0 out of 5)



1. General
     1.1. How does PHK differ from PHAR ?
     1.2. Why isn't it in PEAR ?
     1.3. Why don't you set a 'shebang" line in CLI packages ?
     1.4. May I freely distribute the PHK packages I create ?
     1.5. How can I help ?
2. Troubleshooting
     2.1. Constant __COMPILER_HALT_OFFSET__ already defined
     2.2. Fatal error: __HALT_COMPILER() can only be used once per request
     2.3. I get a lot of '?' when executing/including a package
     2.4. 'No input file specified'


1 - General

1.1 - How does PHK differ from PHAR ?

The original version of this chapter was removed when releasing PHK V 3.0.0 because the information it contained was obsolete, and because I am not the right one to write a detailed comparison of both systems.

From a feature point of view, I'll just say that PHK probably includes more high-level features like the transparent integrated autoloader, meta-information, multiple entry points, nested packages, plugins, the webinfo mode, builtin CLI commands... While I consider all of these as potential benefits for my users, phar authors used to consider that providing high-level features restricts user freedom. So, they prefer providing basic features only. Unfortunately, users are not all willing to program their own high-level features, and the features provided by PHK don't restrict user's freedom in any way, as they are always optional.

Well, as you can see, we didn't agree and I suspect it won't change soon...

1.2 - Why isn't it in PEAR ?

It could, one day. The potential problems to solve are :

  • phkmgr does not use the PEAR installer.
  • The PHK code does not use any of the PEAR base classes.
  • The source code is not totally compliant with the PEAR standards.

1.3 - Why don't you set a 'shebang" line in CLI packages ?

On Unix/Linux systems, packages to be used as CLI commands may include a first line (named 'shebang' line) starting with '#!' and indicating which command must be used to run this script. Then, you just need to make the script executable and put it in your path. This way, the script can be executed directly by the system.

Unfortunately, this works only in CLI mode. Such a script, when included from another script, or run during a web request, will display the 'shebang' line.

The same PHK package may be executed as a CLI commands, but also as included file and in a web request, using multiple entry points. automap.phk, for instance, is used as a map file manager AND as runtime library. In such a case, inserting a shebang line by default would cause the shebang line to be displayed when the package is used as a library.

Setting a shebang line on CLI-only PHK packages is possible using the '@set_interp' builtin command. For instance, here are the commands to build an executable 'mypackage' command from a PHK package (searching for the PHP interpreter in the path) :

cp mypackage.phk mypackage
php mypackage @set_interp '/usr/bin/env php'
chmod +x mypackage

Now, 'mypackage' is an executable command that can be put in your path.

1.4 - May I freely distribute the PHK packages I create ?

Yes, the PHK Creator software is distributed under the Apache license, Version 2.0. It does not impose any license constraint on the generated packages.

1.5 - How can I help ?

First and most important, if you are using PHK and have ideas of possible enhancements, please fill an issue. Don't be shy, ideas are always welcome. 

You can also write articles, tutorials, or just talk to your friends about it. Ask for help when needed.

If you really like PHK, I have an Amazon wishlist... I would be quite surprised if someone bought something there but, who knows ? :)

2 - Troubleshooting

2.1 - Constant __COMPILER_HALT_OFFSET__ already defined

This issue is supposed to be fixed since PHP 5.2.2. If you get this, please report as a bug with as many details as possible.

2.2 - Fatal error: __HALT_COMPILER() can only be used once per request

This issue is supposed to be fixed since PHP 5.2.2. If you get this, please report as a bug with as many details as possible.

2.3 - I get a lot of '?' when executing/including a package

This problem is caused by bug #42396. When unicode detection is active (PHP configured with --enable-zend-multibyte option), PHK packages are detected as unicode scripts (because they contain null bytes). The issue is the same with phar packages.

I have submitted a patch for PHP. Unfortunately, it was refused. So, the only workaround is to add this line to your php.ini file :

detect_unicode=Off

2.4 - 'No input file specified'

If you use web direct access through a CGI SAPI, you may experience some error messages saying : 'No input file specified'. This is a well-known problem, and you can find a lot of information on the web about it.

The usual solution is to use mod_rewrite directives in a .htaccess file in the directory where your PHK archives lie. This rewriting uses the fact that, in web direct access mode, PHK provides two ways to specify the subfile's internal path:

  • either as a subpath in the original URL, like: http://server/path/to/phk/virtual/path/to/subfile. Your users will always see this kind of URLs in their browsers.
  • or in the global variable $_REQUEST|'_phk_path']. This way, the same URL is rewritten as : http://server/path/to/phk?_phk_path=/virtual/path/to/subfile. This URL works in CGI mode.

Here, we are using mod_rewrite to translate the first format to the second one.

As mod_rewrite can be quite complex to configure, we will only give, as an example, what we use for the demos on this web site. You will probably need to adapt it. More info on mod_rewrite here :

# Rewrite rules to allow PHK web access through CGI

RewriteEngine on

#-- Use RewriteBase if the URL directory does not correspond
#-- to the physical directory (Alias)

#RewriteBase /demo

#-- This is the rule.
#-- [qsappend] allows to keep an optional query string in the source URL

RewriteRule ^([^/]+)\.php5/(.*)$ /demo/$1.php5?_phk_path=/$2 [qsappend]

 

Please login or register to add a comment