POT
POT
POT
Main menu

Download

Forum

SVN

Prev Next

PHAR package

Next distribution packet format.

Table of Contents

What is PHAR

PHAR is another format of PHP distribution packages. Generaly, it's idea is very similar to PHK packages, but it differs in many technical aspects. You can find more info about PHAR in PHP manual.

The most important difference is, that PHAR requires additional binary extension (PHK packages work just as PHP files, you don't need any additional extensions) which means people who don't know how to use PECL or simply people who won't be able to compile own extensions will be unable to use PHAR archives.

How to use

Unfortunately PHAR extension requires PHP in version 5.2 or newer so if you don't have such then you won't be able to work with PHAR archives.

The only difference between PHK and PHAR archives is that PHAR archives are transparently visible as files tree so you only change the location of OTS.php file. Rest of your code stays unaffected - nothing changes like with PHK archive. Here is simple startup script:

  1. <?php
  2.  
  3. // includes POT package
  4. include_once('phar://POT.phar/classes/OTS.php');
  5.  
  6. // database configuration - can be simply moved to external file, eg. config.php
  7. $config array(
  8.     'driver' => POT::DB_MYSQL,
  9. //    'prefix' => '',
  10.     'host' => 'localhost',
  11.     'user' => 'wrzasq',
  12. //    'password' => '',
  13.     'database' => 'otserv'
  14. );
  15.  
  16. // creates POT instance (or get existing one)
  17. $ots POT::getInstance();
  18. $ots->connect(null$config);
  19. // could be: $ots->connect(POT::DB_MYSQL, $config);
  20.  
  21. ?>

As you can see it differes from normal startup script and PHK startup script only with file inclusion line.

Development notes

To work with PHAR package, whether you want to modify it or only load, you need to have PECL PHAR extension installed in your PHP. You can install it by using 'pecl install phar' (recommended way).

Prev Up Next
PHK package Additional info Deprecations