> For the complete documentation index, see [llms.txt](https://appsecurity.gitbook.io/devops/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://appsecurity.gitbook.io/devops/ppc/ppc-langs/backend/php/examples/phar.md).

# Phar

php.ini:

```ini
[phar]
phar.readonly = 0
```

Create phar:

```php
<?php

$template = new YourObject();
// Create Phar
$file_name = 'test.phar';

$phar = new Phar($file_name);
$phar->startBuffering();
$phar->addFromString("test.txt", "test");
$phar->setStub('$prefix<?php __HALT_COMPILER(); ?>');
$phar->setMetadata($template);
$phar->stopBuffering();

// Get Phar content
$phar_content = file_get_contents($file_name);

?>
```

Run script:

```
$ php -c php.ini create_phar.php
```
