docs/current_docs/extending/custom-applications/php.mdx
:::note The Dagger PHP SDK requires PHP 8.2 or later. :::
Install the Dagger PHP SDK in your project using composer:
composer require dagger/dagger
This example demonstrates how to test a PHP application against multiple PHP versions using the PHP SDK.
Clone an example project:
git clone https://github.com/slimphp/Slim-Skeleton.git
cd Slim-Skeleton
Create a new file named test.php in the project directory and add the following code to it.
This PHP program imports the Dagger SDK and defines a function named test(). This test() function creates a Dagger client, which provides an interface to the Dagger API. It also defines the test matrix, consisting of PHP versions 8.2 to 8.4 and iterates over this matrix, downloading a PHP container image for each specified version and testing the source application in that version.
Run the PHP program by executing the command below from the project directory:
dagger run php test.php
The dagger run command executes the specified command in a Dagger session and displays live progress. The program tests the application against each version concurrently and displays the following final output:
Starting tests for PHP 8.2...
PHPUnit 9.6.22 by Sebastian Bergmann and contributors.
Warning: Your XML configuration validates against a deprecated schema.
Suggestion: Migrate your XML configuration using "--migrate-configuration"!
................... 19 / 19 (100%)
Time: 00:00.038, Memory: 12.00 MB
OK (19 tests, 37 assertions)
Completed tests for PHP 8.2
**********
Starting tests for PHP 8.3...
PHPUnit 9.6.22 by Sebastian Bergmann and contributors.
Warning: Your XML configuration validates against a deprecated schema.
Suggestion: Migrate your XML configuration using "--migrate-configuration"!
................... 19 / 19 (100%)
Time: 00:00.039, Memory: 12.00 MB
OK (19 tests, 37 assertions)
Completed tests for PHP 8.3
**********