home / skills / windmill-labs / windmill / write-script-php
This skill guides you in writing PHP scripts by structuring main function, resource types, and required libraries for Windmill workflows.
npx playbooks add skill windmill-labs/windmill --skill write-script-phpReview the files below or copy the command above to add this skill to your agents.
---
name: write-script-php
description: MUST use when writing PHP scripts.
---
## CLI Commands
Place scripts in a folder. After writing, run:
- `wmill script generate-metadata` - Generate .script.yaml and .lock files
- `wmill sync push` - Deploy to Windmill
Use `wmill resource-type list --schema` to discover available resource types.
# PHP
## Structure
The script must start with `<?php` and contain at least one function called `main`:
```php
<?php
function main(string $param1, int $param2) {
return ["result" => $param1, "count" => $param2];
}
```
## Resource Types
On Windmill, credentials and configuration are stored in resources and passed as parameters to main.
You need to **redefine** the type of the resources that are needed before the main function. Always check if the class already exists using `class_exists`:
```php
<?php
if (!class_exists('Postgresql')) {
class Postgresql {
public string $host;
public int $port;
public string $user;
public string $password;
public string $dbname;
}
}
function main(Postgresql $db) {
// $db contains the database connection details
}
```
The resource type name has to be exactly as specified.
## Library Dependencies
Specify library dependencies as comments before the main function:
```php
<?php
// require:
// guzzlehttp/guzzle
// stripe/stripe-php@^10.0
function main() {
// Libraries are available
}
```
One dependency per line. No need to require autoload, it is already done.
This skill guides you to write PHP scripts that run on the Windmill platform. It explains the required script structure, how to declare resource types, and how to list runtime library dependencies so your script runs as a deployable Windmill task. It also covers the basic CLI steps to generate metadata and push scripts to the platform.
Scripts must begin with the PHP opening tag and expose a main function that Windmill will call with parameters. Credentials and configuration are modeled as resource objects; you must redefine resource classes in your script (guarded by a class_exists check) so Windmill can marshal those resources into typed parameters. External libraries are declared as in-file comments and are auto-installed for the runtime.
How do I ensure the platform passes credentials into my script?
Define a class with the exact resource type name and fields you expect, guarded by class_exists. Windmill will instantiate and pass it to your main function.
How do I add third-party PHP libraries?
List each package on its own comment line before main using the require: comment format. The runtime installs them and autoloading is already handled.