Handy PHP Functions when Working with PHAR Archives

PHAR is an acronym for PHP Archive. It allows putting entire PHP applications into a single .phar file. Here are some handy functions for working with PHAR files.

Handy PHP Functions when Working with PHAR Archives

If yu have been in PHP long enough you will have heard about PHAR. If you have not the PHAR is an acronym for PHP Archive. It allowes to put entire PHP applications into a single ".phar" file. This is quite handy for lots of different situations.

If you need to work with creating PHAR files, here are some handy functions to get you going:

1. Determine if PHP is Running from a PHAR Archive


function isPhar() {
  return strlen(Phar::running()) > 0 ? true : false;
}

2. Determine the Running Directory of the PHAR file


function getRunningDir() {
  if(strlen(Phar::running()) > 0){
    $pharDir = Phar::running(false);
    return dirname($pharDir);
  }
  return __DIR__;
}

Happy PHAR-ing :)

Previous
2017 - Comparison of VPS Hosting Prices
Next
Solved. Laravel 5. TokenMismatchException in VerifyCsrfToken

Keep Reading

Explore more articles and insights

Ork: SSH Server Automation in Go

Ork: SSH Server Automation in Go

Read Article
Deno Deploy Killed My Start Page

Deno Deploy Killed My Start Page

Read Article
Back to Golang: Why I Switched From Static to Dynamic Again

Back to Golang: Why I Switched From Static to Dynamic Again

Read Article
View All Blog Posts