Download the PHP package jalle19/haphproxy without Composer
On this page you can find all versions of the php package jalle19/haphproxy. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package haphproxy
haphproxy
haphproxy is a PHP library which can parse and create HAproxy configuration files.
The library operates on the configuration at a low level. A configuration is made up of sections (e.g. global
and
default
). Each section is made up of parameters (e.g. mode
and timeout
). Each parameter has a value associated
with it, e.g. a parameter named timeout
can have a value of timeout 30s
.
Since the library doesn't actually understand how HAproxy works, it is only guaranteed to generate syntactically valid
configurations. For proper validation, please use haproxy -f <configurationFile> -c
.
Requirements
- PHP 5.6 or newer
Installation
Install via Composer:
Usage
Reading a configuration
This example reads an existing configuration file, parses it and dumps it back as a string:
Writing a configuration
This example shows how you can dynamically create a configuration:
The above results in the following configuration being generated:
Changing the output formatting
You can change the indentation and preface of the generated configuration. Changing the preface may be useful when used in combination with other tools to indicate whether the configuration file has been generated dynamically or not.
Inspecting a configuration
You can access the individual parameters of each section like this:
You can also loop through specific sections of a configuration:
Magic comments
A magic comment is a comment that beings with HAPHPROXY_COMMENT
. In contrast to normal comments, these are not
omitted during parsing and writing. Magic comments only apply to sections and can be useful to store arbitrary data.
The above results in the following configuration being generated:
Testing
The test suite leaves all the validation of the generated configurations to HAproxy itself, so in order to run the test
suite you'll need to have haproxy
in your path. To run the test suite, run php vendor/bin/phpunit
.
There is a Vagrantfile
shipped with the library which automatically provisions itself with all the required software.
License
This library is licensed under the GNU General Public License 2 or newer