phar

Advantages of PHAR archives in PHP

久未见 提交于 2019-12-02 23:17:46
PHP 5.3 has a new feature called PHAR similar to JAR in JAVA. It's basically a archive of PHP files. What are its advantages? I can't understand how they can be helpful in the web scenario. Any other use other than "ease of deployment" - deploy an entire application by just copying one file There are tremendous benefits for open source projects (in no particular order). Easier deployment means easier adoption. Imagine: You install a CMS, forum, or blog system on your website by dragging it into your FTP client. That's it. Easier deployment means easier security. Updating to the latest version

How to make an executable phar?

好久不见. 提交于 2019-12-02 21:14:31
I want to start a phar script as an executable, directly by doing foo.phar <params> instead of php foo.phar <params> . It's easy by modifying the default stub (adding the shebang corresponding to php). // start buffering. Mandatory to modify stub. $phar->startBuffering(); // Get the default stub. You can create your own if you have specific needs $defaultStub = $phar->createDefaultStub('index.php'); // Adding files $phar->buildFromDirectory(__DIR__, '/\.php$/'); // Create a custom stub to add the shebang $stub = "#!/usr/bin/php \n".$defaultStub; // Add the stub $phar->setStub($stub); $phar-

Extracting files from .phar archive

怎甘沉沦 提交于 2019-12-02 16:58:42
There is something I entirely missed as for phar files. I am installing a project that requires phpunit, pdepend and other dependencies. I fetched them as .phar files. But, I am not able ot extract the files from them using command line tool (php command). I googled the problem, and I found nothing really answering the question. Could anyone help ? Yes, this library can do it: https://github.com/koto/phar-util phar-extract library.phar output-directory Extending on @pozs’s answer, you can actually use PharData->extractTo in a simple one-liner: php -r '$phar = new Phar("phar-file.phar"); $phar-

Phar archive no read and write permissions with symfony filesystem

妖精的绣舞 提交于 2019-12-02 16:23:35
问题 i have created a cli app which tries to create a file with symfony 3 fileSystem component. All works fine, but if i put the app in a phar archive symfony can't write the file. This is how i created the phar archive: <?php $phar = new Phar('app.phar', 0, 'app.phar'); $phar->buildFromDirectory(dirname(__FILE__) ); $phar->setStub($phar->createDefaultStub('app.php')); The app.php call the symfony filesystem component: <?php .... $this->fileSystem->dumpFile( 'testfile.txt', 'my test content' );

Phar: re-use .htaccess-defined rewrite rules

江枫思渺然 提交于 2019-12-02 04:57:59
My PHP project has a dozen URL rewriting rules listed in .htaccess. Now I want to provide the application as a .phar file and thus need to re-implement the rewrite rules the rewrite function that can be passed to Phar::webPhar() as 4th parameter. Is there a way to re-use the .htaccess rewrite rules in my php code without implementing them in PHP directly? Some library/extension/code that just "interprets" them? Before packaging up the .phar file, I generate a PHP array of regex pattern from the .htaccess file with build-rewritemap.php . The rewrite handler of Phar::webPhar() then iterates over

PharData class fails when tar contents has relative paths

家住魔仙堡 提交于 2019-12-02 04:03:45
问题 I'm having trouble with using Phar to access gzipped tar files. Here's my test code: <?php function r($a) { print " has " . count($a) . " files:\n"; foreach (new RecursiveIteratorIterator($a) as $path => $fileinfo) { print " " . $path . "\n"; } } print "\n1.tgz"; r(new PharData('1.tgz')); print "\n2.tgz"; r(new PharData('2.tgz')); print "\norig dir:"; chdir('orig-dir'); r(new RecursiveDirectoryIterator('./')); Here's the fixture: mkdir -p orig-dir/subdir; touch orig-dir/{a,b,subdir/c}; cd

PharData class fails when tar contents has relative paths

痴心易碎 提交于 2019-12-02 00:30:42
I'm having trouble with using Phar to access gzipped tar files. Here's my test code: <?php function r($a) { print " has " . count($a) . " files:\n"; foreach (new RecursiveIteratorIterator($a) as $path => $fileinfo) { print " " . $path . "\n"; } } print "\n1.tgz"; r(new PharData('1.tgz')); print "\n2.tgz"; r(new PharData('2.tgz')); print "\norig dir:"; chdir('orig-dir'); r(new RecursiveDirectoryIterator('./')); Here's the fixture: mkdir -p orig-dir/subdir; touch orig-dir/{a,b,subdir/c}; cd orig-dir tar czf ../1.tgz * tar czf ../2.tgz ./ cd ../ # put the test code file here and run with php test

Can I package PHPUnit as a phar?

牧云@^-^@ 提交于 2019-12-01 02:25:38
问题 I would like to package PHPUnit and various other test dependencies into a phar and put that into svn. This way I can run phpunit on any client machine without needing pear. Can this be done? 回答1: Current status: Work on a phpunit.phar has started in the phpunit repo but the generated phar is not stable and not feature complete. If it gets there there will be official releases Original answer: If you can I'll give you 500 rep, a 100 Bucks and my first born.. well no.. just the first two. To

How to use PHP Composer on HostGator

为君一笑 提交于 2019-11-29 20:19:13
I recently decided to start a project in Zend Framework 2 and was having trouble getting it to run on a HostGator shared server. By default, HostGator's shared servers run in PHP 5.2.2 and if you upload the ZF2 Skeleton Application, it will not run out of the box. Also, if you happen to have SSH access to your HG Shared account (You usually have to request it), you won't be able to run .PHAR files because the CLI version of PHP is also 5.2.2. Luckily, I got it to work... see below. First off, you can enable PHP 5.3 on HostGator on a directory level basis. Simply add the following line to the

Installing Laravel 4.1 in Windows 7 // Make .phar file globally available to windows command line

心已入冬 提交于 2019-11-28 17:20:26
i have some problems installing Laravel 4.1 in Windows 7 via the first method explained in the Laravel documentation ( http://laravel.com/docs/installation#install-laravel ). So I downloaded the laravel.phar file and put it in my path ( System32 ). Which would be the equivalent of /usr/bin in linux based systems? ( I also added .PHAR in the PATHEXT system variable ). When i ran the laravel command from the command line it didn't know how to open it, so i chose to open it with php.exe. Now, when I run the composer command it says: "Could not open input file: C:\Windows\system32\laravel.phar". I