Artillery
in package
Main class for Artillery scripts, containing all methods for config and adding scenarios.
Tags
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Return values
$this —The current Artillery instance.
setHttp()
Set an option in the http property of the config section in the Artillery script.
public
setHttp(string $key, int|bool $value) : $this
Parameters
- $key : string
- $value : int|bool
-
The value of the option.
Tags
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
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
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
Return values
$this —The current Artillery instance.
setHttpTimeout()
Set the timeout option for the http property in the config section of the Artillery script.
public
setHttpTimeout(int $timeout) : $this
Parameters
- $timeout : int
-
The timeout in seconds.
Tags
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
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
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
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
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
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
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
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
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
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
Return values
WsRequest —A new WsRequest instance.