Documentation

Artillery
in package

Main class for Artillery scripts, containing all methods for config and adding scenarios.

Tags
example
use ArtilleryPhp\Artillery;

// Create a new Artillery instance
$artillery = Artillery::new('http://localhost:3000')
    ->addPhase(['duration' => 60, 'arrivalRate' => 5, 'rampTo' => 20], 'Warm up')
    ->addPhase(['duration' => 60, 'arrivalRate' => 20], 'Sustain')
    ->setPlugin('expect');

// Define the flow of your scenario and add it to the Artillery instance
$flow = Artillery::scenario()
    ->addRequest(
        Artillery::request('get', '/login')
            ->addCapture('token', 'json', '$.token')
            ->addExpect('statusCode', 200)
            ->addExpect('contentType', 'json')
            ->addExpect('hasProperty', 'token'))
    ->addRequest(
        Artillery::request('get', '/inbox')
            ->setQueryString('token', '{{ token }}')
            ->addExpect('statusCode', 200));

$scenario = Artillery::scenario()->addLoop($flow, 10);

$artillery->addScenario($scenario);

// Export the YAML
file_put_contents(__DIR__ . '/artillery.yaml', $artillery->toYaml());
link
https://www.artillery.io/docs/guides/guides/test-script-reference

Table of Contents

addEnsureCondition()  : $this
Adds an 'ensure' condition to the Artillery script. Metrics are listed in the report output.
addEnsureConditions()  : $this
Adds an array of 'ensure' conditions to the Artillery script. Metrics are listed in the report output.
addEnsureThreshold()  : $this
Adds an 'ensure' threshold to the config section of the Artillery script.
addEnsureThresholds()  : $this
Adds an array of 'ensure' thresholds to the config section of the Artillery script.
addPayload()  : $this
Adds a CSV file as payload the config section of the Artillery script.
addPayloads()  : $this
Adds an array of payloads the config section of the Artillery script.
addPhase()  : $this
Adds a phase to the config section of the Artillery script.
addPhases()  : $this
Adds an array of phase to the config section of the Artillery script.
addScenario()  : $this
Adds a Scenario to the main scenarios section of the Artillery script. You can also provide a single Request or array of Requests, and a scenario will be made from it.
addScenarios()  : $this
Adds an array of Scenarios to the main scenarios section of the Artillery script. You can also provide a single Request or array of Requests, and a scenario will be made from it.
anyRequest()  : AnyRequest
Creates an anonymous Request type for custom engines.
build()  : $this
Creates a Yaml file from the current Artillery instance.
from()  : Artillery
Creates a new Artillery instance copy from another Artillery instance.
fromArray()  : Artillery
Creates a new Artillery instance from an array representation.
fromYaml()  : Artillery
Creates a new Artillery instance from a YAML file.
merge()  : self
Merge another Artillery instance into this one.
new()  : self
Creates a new Artillery instance, optionally with a target URL.
request()  : Request
Creates a new Request for HTTP Scenarios with the given HTTP method and URL.
run()  : $this
Run the Artillery script using passthru('artillery run ...') and create a report file.
scenario()  : Scenario
Creates a new Scenario which contains a Flow of Requests.
set()  : $this
Set an arbitrary option in the config section of the Artillery script, such as custom engine settings.
setAfter()  : $this
Set a Scenario, Request or array of Requests to the 'after' section of the Artillery script, which will be executed after a scenario.
setBefore()  : $this
Set a Scenario, Request or array of Requests to the 'before' section of the Artillery script, which will be executed before a main scenario.
setEngine()  : $this
Set a the engine to the config section of the Artillery script.
setEngines()  : $this
Set an array of custom engine to the config section of the Artillery script.
setEnvironment()  : $this
Adds an environment to the config's environments section of the Artillery script with environment-specific config overrides.
setEnvironments()  : $this
Adds an array of environments to the config's environments section of the Artillery script.
setHttp()  : $this
Set an option in the http property of the config section in the Artillery script.
setHttpExtendedMetrics()  : $this
The HTTP engine can be configured to track additional performance metrics by setting extendedMetrics to true.
setHttpMaxSockets()  : $this
By default, Artillery creates one TCP connection per virtual user. To allow for multiple sockets per virtual user (to mimic the behavior of a web browser, for example), specify the number of connections.
setHttps()  : $this
Set an array of options for the http property in the config section of the Artillery script.
setHttpTimeout()  : $this
Set the timeout option for the http property in the config section of the Artillery script.
setPlugin()  : $this
Enables a plugin in the config section of the Artillery script.
setPlugins()  : $this
Enables an array of plugin (just names or with options as value) in the config section of the Artillery script.
setProcessor()  : $this
Set the JavaScript processor file for the Artillery script.
setTarget()  : $this
Set the target url property of the config section of the Artillery script, used as the base url for requests.
setTls()  : $this
Reject self-signed Tls certificates.
setVariable()  : $this
Set a variable in the config section of the Artillery script.
setVariables()  : $this
Set an array of variables in the config section of the Artillery script.
setWs()  : $this
Set the ws property of the config section of the Artillery script.
toArray()  : array<string|int, mixed>
Get the current Artillery script as an array.
toYaml()  : string
Export the Artillery script as YAML string.
wsRequest()  : WsRequest
Creates a new WsRequest for WebSocket (engine: ws) Scenarios with the given method and request data.

Methods

addEnsureCondition()

Adds an 'ensure' condition to the Artillery script. Metrics are listed in the report output.

public addEnsureCondition(string $expression[, bool $strict = null ]) : $this
Parameters
$expression : string

The expression to be used as a condition.

$strict : bool = null

If set to false, the condition is not strict.

Tags
description

Artillery can validate if a metrics value meets a predefined threshold. If it doesn't, it will exit with a non-zero exit code.
Setting strict: false on a condition will make that check optional. Failing optional checks do not cause Artillery to exit with a non-zero exit code. Checks are strict by default.
The built-in 'ensure' plugin needs to be enabled with Artillery::setPlugin('ensure') for this feature.

example
$artillery = Artillery::new()
    ->setPlugin('ensure')
    ->addEnsureCondition('http.response_time.p95 < 250 and http.request_rate > 1000');
link
https://www.artillery.io/docs/guides/guides/test-script-reference#advanced-conditional-checks
link
https://www.artillery.io/docs/guides/guides/test-script-reference#ensure---slo-checks
link
https://www.artillery.io/docs/guides/plugins/plugins-overview
Return values
$this

The current Artillery instance.

addEnsureConditions()

Adds an array of 'ensure' conditions to the Artillery script. Metrics are listed in the report output.

public addEnsureConditions(array<string|int, mixed> $thresholds) : $this
Parameters
$thresholds : array<string|int, mixed>
Tags
description

Artillery can validate if a metrics value meets a predefined threshold. If it doesn't, it will exit with a non-zero exit code.
Setting strict: false on a condition will make that check optional. Failing optional checks do not cause Artillery to exit with a non-zero exit code. Checks are strict by default.
The built-in 'ensure' plugin needs to be enabled with Artillery::setPlugin('ensure') for this feature.

example
$artillery = Artillery::new()
    ->setPlugin('ensure')
    ->addEnsureConditions([
        ['expression' => 'http.response_time.p95 < 250 and http.request_rate > 1000'],
        ['expression' => 'http.response_time.p99 < 500', 'strict' => false],
    );
link
https://www.artillery.io/docs/guides/guides/test-script-reference#advanced-conditional-checks
link
https://www.artillery.io/docs/guides/guides/test-script-reference#ensure---slo-checks
link
https://www.artillery.io/docs/guides/plugins/plugins-overview
Return values
$this

The current Artillery instance.

addEnsureThreshold()

Adds an 'ensure' threshold to the config section of the Artillery script.

public addEnsureThreshold(string $metricName, int $value) : $this
Parameters
$metricName : string

The name of the metric to be used as a threshold.

$value : int

The threshold value.

Tags
description

Artillery can validate if a metrics value meets a predefined threshold. If it doesn't, it will exit with a non-zero exit code.
The built-in 'ensure' plugin needs to be enabled with Artillery::setPlugin('ensure') for this feature.

example
$artillery = Artillery::new()
    ->setPlugin('ensure')
    ->addEnsureThreshold('http.response_time.p99', 250)
    ->addEnsureThreshold('http.response_time.p95', 100);
link
https://www.artillery.io/docs/guides/guides/test-script-reference#threshold-checks
Return values
$this

The current Artillery instance.

addEnsureThresholds()

Adds an array of 'ensure' thresholds to the config section of the Artillery script.

public addEnsureThresholds(array<string|int, array<string, int>> $thresholds) : $this
Parameters
$thresholds : array<string|int, array<string, int>>

An array of thresholds to add to the config section of the Artillery script.

Tags
description

Artillery can validate if a metrics value meets a predefined threshold. If it doesn't, it will exit with a non-zero exit code.
The built-in 'ensure' plugin needs to be enabled with Artillery::setPlugin('ensure') for this feature.

example
$artillery = Artillery::new()
    ->setPlugin('ensure')
    ->addEnsureThresholds([
        ['http.response_time.p99' => 250],
	       ['http.response_time.p95' => 100]]);
Return values
$this

The current Artillery instance.

addPayload()

Adds a CSV file as payload the config section of the Artillery script.

public addPayload(string $path, array<string|int, mixed> $fields[, array<string|int, mixed> $options = [] ]) : $this
Parameters
$path : string

The path of the payload file.

$fields : array<string|int, mixed>

The fields to be used from the payload file.

$options : array<string|int, mixed> = []
Tags
description

You can use a CSV file to provide dynamic data to test scripts.
For example, you might have a list of usernames and passwords that you want to use to test authentication in your API.
Payload file options:

  • order (default: random) - Control how rows are selected from the CSV file for each new virtual user. This option may be set to sequence to iterate through the rows in a sequence (looping around and starting from the beginning after reaching the last row). Note that this will not work as expected when running distributed tests, as each node will have its own copy of the CSV data.
  • skipHeader (default: false) - Set to true to make Artillery skip the first row in the file (typically the header row).
  • delimiter (default: ,) - If the payload file uses a delimiter other than a comma, set this option to the delimiter character.
  • cast (default: true) - By default, Artillery will convert fields to native types (e.g. numbers or booleans). To keep those fields as strings, set this option to false.
  • skipEmptyLines (default: true) - By default, Artillery skips empty lines in the payload. Set as false to include empty lines.
  • loadAll and name - set loadAll to true to provide all rows to each VU, and name to a variable name which will contain the data
example
$artillery = Artillery::new()
    ->addPayload('users.csv', ['username', 'password'], ['skipHeader' => true])
    ->addScenario(Artillery::request('post', '/login')
        ->setJsons(['username' => '{{ username }}', 'password' => '{{ password }}']));
link
https://www.artillery.io/docs/guides/guides/test-script-reference#payload---loading-data-from-csv-files
Return values
$this

The current Artillery instance.

addPayloads()

Adds an array of payloads the config section of the Artillery script.

public addPayloads(array<string|int, mixed> $payloads) : $this
Parameters
$payloads : array<string|int, mixed>
Tags
description

You can use a CSV file to provide dynamic data to test scripts.
For example, you might have a list of usernames and passwords that you want to use to test authentication in your API.
Payload file options:

  • path - Path to the CSV file
  • fields - Names of variables to use for each column in the CSV file
  • order (default: random) - Control how rows are selected from the CSV file for each new virtual user. This option may be set to sequence to iterate through the rows in a sequence (looping around and starting from the beginning after reaching the last row). Note that this will not work as expected when running distributed tests, as each node will have its own copy of the CSV data.
  • skipHeader (default: false) - Set to true to make Artillery skip the first row in the file (typically the header row).
  • delimiter (default: ,) - If the payload file uses a delimiter other than a comma, set this option to the delimiter character.
  • cast (default: true) - By default, Artillery will convert fields to native types (e.g., numbers or booleans). To keep those fields as strings, set this option to false.
  • skipEmptyLines (default: true) - By default, Artillery skips empty lines in the payload. Set as false to include empty lines.
  • loadAll and name - set loadAll to true to provide all rows to each VU, and name to a variable name which will contain the data
example
$defaultPayloads = [
    ['path' => 'users.csv', 'fields' => ['username', 'password'], 'skipHeader' => true]
    ['path' => 'animals.csv', 'fields' => ['name', 'specie'], 'skipHeader' => true]
];

$artillery = Artillery::new()
    ->addPayloads($defaultPayloads)
    ->addScenario(
        Artillery::scenario()
            ->addRequest(Artillery::request('post', '/login')
            ->setJsons(['username' => '{{ username }}', 'password' => '{{ password }}']))
            ->addRequest(Artillery::request('get', '/animals')
            ->setJsons(['name' => '{{ name }}', 'specie' => '{{ specie }}']))
    );
link
https://www.artillery.io/docs/guides/guides/test-script-reference#payload---loading-data-from-csv-files
Return values
$this

The current Artillery instance.

addPhase()

Adds a phase to the config section of the Artillery script.

public addPhase(array<string|int, mixed> $phase[, string|null $name = null ]) : $this
Parameters
$phase : array<string|int, mixed>
$name : string|null = null

The name of the phase.

Tags
description

A load phase defines how Artillery generates new virtual users (VUs) in a specified time period. For example, a typical performance test will have a gentle warm-up phase, followed by a ramp-up phase, and finalizing with a maximum load for a duration of time.

example
$artillery = Artillery::new()
    ->addPhase(['duration' => 60, 'arrivalRate' => 10], 'warm up')
    ->addPhase(['duration' => 300, 'arrivalRate' => 10, 'rampTo' => 100], 'ramp up')
    ->addPhase(['duration' => 600, 'arrivalRate' => 100], 'sustained load');
link
https://www.artillery.io/docs/guides/guides/test-script-reference#phases---load-phases
Return values
$this

The current Artillery instance.

addPhases()

Adds an array of phase to the config section of the Artillery script.

public addPhases(array<string|int, mixed> $phases) : $this
Parameters
$phases : array<string|int, mixed>
Tags
description

A load phase defines how Artillery generates new virtual users (VUs) in a specified time period. For example, a typical performance test will have a gentle warm-up phase, followed by a ramp-up phase, and finalizing with a maximum load for a duration of time.

example
$defaultPhases = [
    ['duration' => 60, 'arrivalRate' => 10, 'name' => 'warm up'],
    ['duration' => 300, 'arrivalRate' => 10, 'rampTo' => 100, 'name' => 'ramp up'],
    ['duration' => 600, 'arrivalRate' => 100, 'name' => 'sustained load']
];

$artillery = Artillery::new()->addPhases($defaultPhases);
link
https://www.artillery.io/docs/guides/guides/test-script-reference#phases---load-phases
Return values
$this

The current Artillery instance.

addScenario()

Adds a Scenario to the main scenarios section of the Artillery script. You can also provide a single Request or array of Requests, and a scenario will be made from it.

public addScenario(Scenario|RequestInterface|array<string|int, RequestInterface$scenario[, array<string, mixed> $options = null ]) : $this

Optionally, you can provide scenario-level options to set or override for the scenario, such as name or weight.

Parameters
$scenario : Scenario|RequestInterface|array<string|int, RequestInterface>

The Scenario, or Request, or array of requests to add as a new entry in the scenarios section of the script.

$options : array<string, mixed> = null

Scenario level options to set or override for the scenario.

Tags
example
// An extremely simple Artillery script with just one request as a scenario:
$artillery = Artillery::new()->addScenario(Artillery::request('GET', 'https://example.com'));

// More complex Scenario that loops over a set of pages from a target base url:
$scenario = Artillery::scenario()
    ->addRequest(Artillery::request('GET', '/'))
    ->addRequest(Artillery::request('GET', '/about'))
    ->addRequest(Artillery::request('GET', '/contact'));

$artillery = Artillery::new('https://example.com')
    ->addScenario(Artillery::scenario()->addLoop($scenario));
link
https://www.artillery.io/docs/guides/guides/test-script-reference#scenarios-section
Return values
$this

The current Artillery instance.

addScenarios()

Adds an array of Scenarios to the main scenarios section of the Artillery script. You can also provide a single Request or array of Requests, and a scenario will be made from it.

public addScenarios(array<string|int, \ArtilleryPhp\Scenario|\ArtilleryPhp\RequestInterface|\ArtilleryPhp\RequestInterface[]> $scenarios) : $this
Parameters
$scenarios : array<string|int, \ArtilleryPhp\Scenario|\ArtilleryPhp\RequestInterface|\ArtilleryPhp\RequestInterface[]>

An array of Scenarios, or Requests, or arrays of Requests to add as new entries in the scenarios section of the script.

Tags
example
 // Just as addScenario, this function can take a single or array of Requests(s):
$defaultScenarios = [
    // This becomes one scenario:
    Artillery::scenario('Name')
        ->addRequest(Artillery::request('GET', '/'))
        ->addWeight(10),

    // This becomes another scenario:
    Artillery::request('GET', '/about'),

    // This becomes a third scenario:
    [Artillery::request('GET', '/contact'), Artillery::request('GET', '/contact-us')],
];

// Sticking to Scenario objects is recommended as it gives you access to options aside from just the flow such as name and weight.

// Add the 3 scenarios to the Artillery script.
$artillery = Artillery::new()->addScenarios($defaultScenarios);
link
https://www.artillery.io/docs/guides/guides/test-script-reference#scenarios-section
Return values
$this

The current Artillery instance.

anyRequest()

Creates an anonymous Request type for custom engines.

public static anyRequest([string|null $method = null ][, mixed|null $request = null ]) : AnyRequest
Parameters
$method : string|null = null

Method for the Request (e.g., the key for the entry in a flow).

$request : mixed|null = null

Data for the Request (e.g., the value of the $method key).

Tags
example
$emitAndValidateResponse = Artillery::scenario('Emit and validate response')
    ->setEngine('socketio')
    ->addRequest(
        Artillery::anyRequest('emit')
        ->set('channel', 'echo')
        ->set('data', 'Hello from Artillery')
        ->set('response', ['channel' => 'echoResponse', 'data' => 'Hello from Artillery']));
Return values
AnyRequest

A new AnyRequest instance.

build()

Creates a Yaml file from the current Artillery instance.

public build([string|null $file = null ]) : $this
Parameters
$file : string|null = null

Path to the YAML file to create, default is FILE . '.yml'.

Tags
example
$artillery = Artillery::new()
    ->addScenario(Artillery::request('get', 'https://www.example.com'))
    ->build('./artillery.yaml');
Return values
$this

The current Artillery instance.

from()

Creates a new Artillery instance copy from another Artillery instance.

public static from(Artillery $script) : Artillery
Parameters
$script : Artillery

Another Artillery instance.

Return values
Artillery

A new Artillery instance.

fromArray()

Creates a new Artillery instance from an array representation.

public static fromArray(array<string|int, mixed> $script) : Artillery
Parameters
$script : array<string|int, mixed>
Return values
Artillery

A new Artillery instance.

fromYaml()

Creates a new Artillery instance from a YAML file.

public static fromYaml(string $file) : Artillery
Parameters
$file : string

Path to the YAML file.

Return values
Artillery

A new Artillery instance.

merge()

Merge another Artillery instance into this one.

public merge(Artillery $artillery) : self
Parameters
$artillery : Artillery

The Artillery instance to merge into this one.

Tags
example
$config = __DIR__ . '/common-config.yml';
$scenario = __DIR__ . "/scenarios/dino.yml";

$artillery = Artillery::fromYaml($config)
    ->merge(Artillery::fromYaml($scenario));
Return values
self

This Artillery instance.

new()

Creates a new Artillery instance, optionally with a target URL.

public static new([string|null $targetUrl = null ]) : self
Parameters
$targetUrl : string|null = null

Target base URL for the Artillery script.

Return values
self

A new Artillery instance.

request()

Creates a new Request for HTTP Scenarios with the given HTTP method and URL.

public static request([string $method = null ][, string|null $url = null ]) : Request
Parameters
$method : string = null
$url : string|null = null

URL for the request, will be appended to the target URL set in config: target but can also be a fully qualified URL.

Tags
link
https://www.artillery.io/docs/guides/guides/http-reference#get--post--put--patch--delete-requests
Return values
Request

A new Request instance.

run()

Run the Artillery script using passthru('artillery run ...') and create a report file.

public run([string|null $reportFile = null ][, string|null $debug = null ]) : $this
Parameters
$reportFile : string|null = null

Path to the report file to create, default is FILE . '-report-' . time() . '.json'.

$debug : string|null = null

If set, command is run with 'DEBUG=$debug ' prefix. E.g. 'http,http:response'.

Tags
example
$artillery = Artillery::new()
    ->addScenario(Artillery::request('get', 'https://www.example.com'))
    ->run();
Return values
$this

The current Artillery instance.

scenario()

Creates a new Scenario which contains a Flow of Requests.

public static scenario([string $name = null ]) : Scenario
Parameters
$name : string = null
Tags
link
https://www.artillery.io/docs/guides/getting-started/writing-your-first-test#scenarios
link
https://www.artillery.io/docs/guides/overview/why-artillery#scenarios
link
https://www.artillery.io/docs/guides/guides/test-script-reference#overview
link
https://www.artillery.io/docs/guides/guides/test-script-reference#scenarios-section
Return values
Scenario

A new Scenario instance.

set()

Set an arbitrary option in the config section of the Artillery script, such as custom engine settings.

public set(string $key, mixed $value) : $this
Parameters
$key : string

The name of the option in the config section.

$value : mixed

The value of the option.

Return values
$this

The current Artillery instance.

setAfter()

Set a Scenario, Request or array of Requests to the 'after' section of the Artillery script, which will be executed after a scenario.

public setAfter(array<string|int, RequestInterface>|RequestInterface|Scenario $after) : $this
Parameters
$after : array<string|int, RequestInterface>|RequestInterface|Scenario

The Scenario or Request(s) to set as the 'after' scenario.

Tags
link
https://www.artillery.io/docs/guides/guides/test-script-reference#before-and-after-sections
Return values
$this

The current Artillery instance.

setBefore()

Set a Scenario, Request or array of Requests to the 'before' section of the Artillery script, which will be executed before a main scenario.

public setBefore(array<string|int, RequestInterface>|RequestInterface|Scenario $before) : $this
Parameters
$before : array<string|int, RequestInterface>|RequestInterface|Scenario

The Scenario or Request(s) to set as the 'before' scenario.

Tags
link
https://www.artillery.io/docs/guides/guides/test-script-reference#before-and-after-sections
Return values
$this

The current Artillery instance.

setEngine()

Set a the engine to the config section of the Artillery script.

public setEngine(string $name[, array<string|int, mixed>|null $options = null ]) : $this
Parameters
$name : string

The name of the engine.

$options : array<string|int, mixed>|null = null

The options for this engine.

Tags
example
$artillery = Artillery::new('https://artillery.io')
    ->addPhase(['arrivalRate' => 1, 'duration' => 10])
    ->setEngine('playwright')
    ->setProcessor('./flows.js');
Return values
$this

The current Artillery instance.

setEngines()

Set an array of custom engine to the config section of the Artillery script.

public setEngines(array<string|int, array|string> $engines) : $this
Parameters
$engines : array<string|int, array|string>

Engines to set. Either just the name of the engine, or an array with the name as the key and the options as value.

Tags
example
$artillery->setEngines(['custom1', 'custom2' => ['some' => 'setting']]);
Return values
$this

The current Artillery instance.

setEnvironment()

Adds an environment to the config's environments section of the Artillery script with environment-specific config overrides.

public setEnvironment(string $name, Artillery|array<string|int, mixed> $config) : $this

Either as an array or another Artillery instance (just make sure not to have nested environments defined).

Parameters
$name : string

The name of the environment.

$config : Artillery|array<string|int, mixed>

Config overrides for this environment, as an array or another Artillery instance.

Tags
description

When running your performance test, you can specify the environment on the command line using the -e flag.

example
$local = Artillery::new('http://localhost:8080')
    ->addPhase(['duration' => 30, 'arrivalRate' => 1, 'rampTo' => 10])
    ->setHttpTimeout(60);

$production = Artillery::new('https://example.com')
    ->addPhase(['duration' => 300, 'arrivalRate' => 10, 'rampTo' => 100])
    ->setHttpTimeout(30);

$artillery = Artillery::new()
    ->setEnvironment('staging', ['target' => 'https://staging.example.com'])
    ->setEnvironment('production', $production)
    ->setEnvironment('local', $local);
artillery run -e local my-script.yml
example
$artillery->setEnvironment('staging', ['target' => 'https://staging.example.com']);
artillery run -e staging my-script.yml
link
https://www.artillery.io/docs/guides/guides/test-script-reference#environments---config-profiles
Return values
$this

The current Artillery instance.

setEnvironments()

Adds an array of environments to the config's environments section of the Artillery script.

public setEnvironments(array<string, array|\ArtilleryPhp\Artillery> $environments) : $this

Either as arrays or Artillery instances (just make sure not to have nested environments defined).

Parameters
$environments : array<string, array|\ArtilleryPhp\Artillery>

Environment definitions, as arrays or Artillery instances, by name.

Tags
description

When running your performance test, you can specify the environment on the command line using the -e flag.

example
$local = Artillery::new('http://localhost:8080')
    ->addPhase(['duration' => 30, 'arrivalRate' => 1, 'rampTo' => 10])
    ->setHttpTimeout(60);

$production = Artillery::new('https://example.com')
    ->addPhase(['duration' => 300, 'arrivalRate' => 10, 'rampTo' => 100])
    ->setHttpTimeout(30);

$defaultEnvironments = [
    'staging' => ['target' => 'https://staging.example.com'],
    'production' => $production,
    'local' => $local
];

$artillery = Artillery::new()->setEnvironments($defaultEnvironments);
artillery run -e local my-script.yml
example
$artillery->setEnvironment('staging', ['target' => 'https://staging.example.com']);
artillery run -e staging my-script.yml
link
https://www.artillery.io/docs/guides/guides/test-script-reference#environments---config-profiles
Return values
$this

The current Artillery instance.

setHttpExtendedMetrics()

The HTTP engine can be configured to track additional performance metrics by setting extendedMetrics to true.

public setHttpExtendedMetrics([bool $extendedMetrics = true ]) : $this
Parameters
$extendedMetrics : bool = true

Whether to track additional performance metrics.

Tags
description

The following additional metrics will be reported:

  • 'http.dns' Time taken by DNS lookups
  • 'http.tcp' Time taken to establish TCP connections
  • 'http.tls' Time taken by completing TLS handshakes
  • 'http.total' Time for the entire response to be downloaded
Return values
$this

The current Artillery instance.

setHttpMaxSockets()

By default, Artillery creates one TCP connection per virtual user. To allow for multiple sockets per virtual user (to mimic the behavior of a web browser, for example), specify the number of connections.

public setHttpMaxSockets(int $maxSockets) : $this
Parameters
$maxSockets : int

The maximum number of sockets per virtual user.

Tags
link
https://www.artillery.io/docs/guides/guides/http-reference#max-sockets-per-virtual-user
Return values
$this

The current Artillery instance.

setHttps()

Set an array of options for the http property in the config section of the Artillery script.

public setHttps(array<string|int, mixed> $options) : $this
Parameters
$options : array<string|int, mixed>
Tags
example
// Set the timeout to 30 seconds and the maximum number of sockets per virtual user to 1.
$artillery = Artillery::new()->setHttps(['timeout' => 30, 'maxSockets' => 1]);
link
https://www.artillery.io/docs/guides/guides/http-reference#http-specific-configuration
Return values
$this

The current Artillery instance.

setPlugin()

Enables a plugin in the config section of the Artillery script.

public setPlugin(string $name[, array<string|int, mixed>|null $options = null ]) : $this
Parameters
$name : string

The name of the plugin.

$options : array<string|int, mixed>|null = null

The options for the plugin.

Tags
description

Artillery has support for plugins, which can add functionality and extend its built-in features. Plugins can hook into Artillery's internal APIs and extend its behavior with new capabilities.
Plugins are distributed as normal npm packages which are named with an artillery-plugin- prefix, e.g. artillery-plugin-expect.

example
npm install artillery-plugin-expect
// There is built in support for 'expect' and 'ensure' plugins.
$artillery = Artillery::new()->setPlugin('expect');

$expectRequest = Artillery::request('get', '/users/1')
    ->addExpect('statusCode', [200, 201]);

// Others can be handled like this:
$artillery->setPlugin('hls');
$customRequest = Artillery::request('get', '/users/1')
    ->set('hls', ['concurrency' => 200, 'throttle' => 128]);
link
https://www.artillery.io/docs/guides/plugins/plugins-overview
link
https://www.npmjs.com/search?ranking=popularity&q=artillery-plugin-
link
https://www.artillery.io/docs/guides/plugins/plugin-expectations-assertions
link
https://www.npmjs.com/package/artillery-plugin-hls
Return values
$this

The current Artillery instance.

setPlugins()

Enables an array of plugin (just names or with options as value) in the config section of the Artillery script.

public setPlugins(array<string|int, mixed> $plugins) : $this
Parameters
$plugins : array<string|int, mixed>

The plugins to be enabled, e,g, ['name1', 'name2' => [..options]].

Tags
description

Artillery has support for plugins, which can add functionality and extend its built-in features. Plugins can hook into Artillery's internal APIs and extend its behavior with new capabilities.
Plugins are distributed as normal npm packages which are named with an artillery-plugin- prefix, e.g. artillery-plugin-expect.

example
npm install artillery-plugin-expect
// There is built in support for 'expect' and 'ensure' plugins.
$artillery = Artillery::new->setPlugins(['expect', 'ensure'])
    ->addEnsureThreshold('http.response_time.p99', 250)
    ->addEnsureThreshold('http.response_time.p95', 100);

$expectRequest = Artillery::request('get', '/users/1')
    ->addExpect('statusCode', [200, 201]);
link
https://www.artillery.io/docs/guides/plugins/plugins-overview
link
https://www.npmjs.com/search?ranking=popularity&q=artillery-plugin-
link
https://www.artillery.io/docs/guides/plugins/plugin-expectations-assertions
link
https://www.npmjs.com/package/artillery-plugin-hls
Return values
$this

The current Artillery instance.

setProcessor()

Set the JavaScript processor file for the Artillery script.

public setProcessor(string $path) : $this
Parameters
$path : string

The path of the processor js file relative to the artillery script.

Tags
description

Functions can be run as part of a flow, or in the various hooks such as beforeScenario, afterResponse, etc.

example
$artillery->setProcessor('processor.js');
$request = Artillery::request('get', '/users/1')
   ->addFunction('myFunction');
link
https://www.artillery.io/docs/guides/guides/test-script-reference#processor---custom-js-code
Return values
$this

The current Artillery instance.

setTarget()

Set the target url property of the config section of the Artillery script, used as the base url for requests.

public setTarget(string $url) : $this
Parameters
$url : string

The base url of the target, e.g. http://localhost:3000.

Tags
example
$artillery->setTarget('http://localhost:3000');
    ->addScenario(Artillery::request('get', '/users/1'));
Return values
$this

The current Artillery instance.

setTls()

Reject self-signed Tls certificates.

public setTls(bool $rejectUnauthorized) : $this

Set the tls 'rejectUnauthorized' property of the config section of the Artillery script.

Parameters
$rejectUnauthorized : bool

Whether to reject unauthorized tls certificates.

Tags
description

If false, tell Artillery to accept self-signed TLS certificates, which it does not do by default.

link
https://www.artillery.io/docs/guides/guides/test-script-reference#tls---self-signed-certificates
Return values
$this

The current Artillery instance.

setVariable()

Set a variable in the config section of the Artillery script.

public setVariable(string $name, mixed $value) : $this
Parameters
$name : string

The name of the variable, to be referenced later as '{{ name }}'.

$value : mixed

The value of the variable.

Tags
description

Variables can be defined in the config section and used in scenarios as '{{ name }}'.
If you define multiple values for a variable, they will be accessed randomly in your scenarios.

example
// Define 3 users:
$artillery->setVariable('username', ['user1', 'user2', 'user3']);

// Pick a random one for each scenario:
$artillery->addRequest(
   Artillery::request('post', '/login')
     ->setJsons(['username' => '{{ username }}', 'password' => '12345678']);
link
https://www.artillery.io/docs/guides/guides/test-script-reference#variables---inline-variables
Return values
$this

The current Artillery instance.

setVariables()

Set an array of variables in the config section of the Artillery script.

public setVariables(array<string, mixed> $variables) : $this
Parameters
$variables : array<string, mixed>

The variables to be set with name as the key.

Tags
description

Variables can be defined in the config section and used in scenarios as '{{ name }}'.
If you define multiple values for a variable, they will be accessed randomly in your scenarios.

example
// Define 3 users and a password:
$artillery->setVariables([
    'username' => ['user1', 'user2', 'user3'],
    'password' => '12345678']);

// Pick a random one for each scenario:
$artillery->addRequest(
   Artillery::request('post', '/login')
     ->setJsons(['username' => '{{ username }}', 'password' => '{{ password }}']);
link
https://www.artillery.io/docs/guides/guides/test-script-reference#variables---inline-variables
Return values
$this

The current Artillery instance.

setWs()

Set the ws property of the config section of the Artillery script.

public setWs(array<string|int, mixed> $wsOptions) : $this
Parameters
$wsOptions : array<string|int, mixed>
Tags
example
$artillery = Artillery::new()->setWs(['subprotocols' => ['json']);
$artillery->addScenario(Artillery::wsRequest('send', ['message' => 'Hello World!'])
        ->addCapture('response', 'json', '$.message'));
link
https://www.artillery.io/docs/guides/guides/ws-reference#websocket-specific-configuration
link
https://www.artillery.io/docs/guides/guides/ws-reference#subprotocols
link
https://www.artillery.io/docs/guides/guides/ws-reference
description

This is the configuration for WebSocket connections in scenarios using Scenario::setEngine('ws').

Return values
$this

The current Artillery instance.

toArray()

Get the current Artillery script as an array.

public toArray() : array<string|int, mixed>
Return values
array<string|int, mixed>

toYaml()

Export the Artillery script as YAML string.

public toYaml([bool $correctNewlines = true ][, int $inline = PHP_INT_MAX ][, int $indent = 2 ][, int $flags = Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE | Yaml::DUMP_OBJECT_AS_MAP ]) : string
Parameters
$correctNewlines : bool = true

Keep array entries on the same line as its dash notation, try turning this off if you have broken output.

$inline : int = PHP_INT_MAX

The level where you switch to inline YAML.

$indent : int = 2

The number of spaces to use for indentation of nested nodes.

$flags : int = Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE | Yaml::DUMP_OBJECT_AS_MAP

A bit field of Yaml::DUMP_* constants to customize the dumped YAML string.

Tags
link
https://symfony.com/doc/current/components/yaml.html
Return values
string

The YAML representation of the Artillery script.

wsRequest()

Creates a new WsRequest for WebSocket (engine: ws) Scenarios with the given method and request data.

public static wsRequest([string|null $method = null ][, mixed $request = null ]) : WsRequest
Parameters
$method : string|null = null

Method for the WebSocket request.

$request : mixed = null

Data for the WebSocket request.

Tags
link
https://www.artillery.io/docs/guides/guides/ws-reference
Return values
WsRequest

A new WsRequest instance.

Search results