Static functions and shell commands
After the schedule fields, each crontab line contains one command string. This library can interpret that string in a few different ways.
The simplest two are:
- run it as a shell command
- treat it as a PHP callable
Shell commands
Any command that is not recognised as a PHP callable or special cron script is passed to the process runner.
0 2 * * * php bin/nightly-maintenance.php
*/5 * * * * printf 'Heartbeat\n'
The command is executed through proc_open().
If the process exits with a non-zero status, the runner treats that as a failure.
Static function calls
If the command looks like a callable, the library runs it directly in PHP rather than starting a separate process.
0 9 * * 1-5 App\Task\Digest::send
30 17 * * * App\Task\Cleanup::archive("weekly", 50)
This is a good fit when:
- the code already lives in your PHP application
- the task is easier to test as a normal method
- we want Composer autoloading rather than a standalone script entry point
Callable resolution
The callable name is taken from everything before the first ( character.
That means all of these are valid shapes:
App\Task\Digest::send
\App\Task\Digest::send
App\Task\Cleanup::archive("weekly", 50)
If the callable does not exist, the runner raises a function execution error for that line.
Arguments
Function arguments are parsed from the text inside the brackets using CSV-style rules:
App\Task\Cleanup::archive("weekly", 50)
Be aware of two details:
- values are read as strings from the crontab line
- double quotes are the clearest way to include spaces or commas
In practice, PHP will usually coerce those strings into scalar parameter types when the method signature expects int, float, or bool, but it is best to keep the arguments simple.
When to choose which style
Prefer a shell command when:
- the task already exists as a standalone script
- the process should be isolated from the current PHP process
- the command naturally belongs to another executable
Prefer a static method when:
- the task is application code
- we want to use Composer autoloading directly
- we do not need a separate process boundary
If the task belongs in the project’s cron/ directory, continue with Cron directory scripts and Go function scripts.