Define background jobs in standard crontab format and the Cron Runner will execute them when they are due. Jobs can be either normal scripts, or calls to static functions with automatic autoloading taken care of.
crontab file within your project directory:
00 * * * * ExampleClass::hourlyTask()
0 22 * * 1-5 YourApp\Accounts\Daily::nightRoutine("you can pass properties too!")
# This is a comment. The above job will run at 10pm Mon-Fri.
*/10 * * * * ExampleClass::runEveryTenMinutes
Start the Runner: vendor/bin/cron.
A missing crontab is a normal no-op: the command prints a skip message and exits successfully with status 0, including in watch, validate and explain modes. Existing malformed crontab files still report an error.
If you're using WebEngine, the Cron Runner is automatically started for you by running gt run.
There is an example directory with numbered scripts that can be run directly with php. Each one embeds its own crontab string so the schedule and output stay together.
JetBrains Open Source sponsorship program
From your application's root directory, generate its service file:
gt cron --generate-service
# Without GtCommand: vendor/bin/cron --generate-serviceThis writes cron.service in the current project directory (replacing a previous
version). It validates the project's crontab without executing jobs. Defaults are
inferred from the project: the owner UID and group GID of vendor, the current
working directory, the running PHP executable, and vendor/bin/cron. Restart delay
is 10 seconds. Numeric UID/GID values are accepted by systemd.
Override individual settings when needed:
gt cron --generate-service --user www-data --group www-data \
--working-directory /var/www/phpgt/www.php.gt \
--php-binary /usr/bin/php --cron-binary /var/www/phpgt/www.php.gt/vendor/bin/cron \
--restart-seconds 15Relative override paths resolve against the current project directory. Even with a working-directory override, the generated file stays in the current project root. Review it, then install with system privileges:
sudo vendor/bin/cron --install-service
# Or: sudo gt cron --install-serviceInstallation symlinks cron.service into /etc/systemd/system, using the current
project directory's basename followed by -cron.service, reloads systemd, and
enables startup at boot and starts the service immediately using
systemctl enable --now. If cron.service is missing, --install-service generates
it first, using the same defaults and overrides as --generate-service. An existing
service file is installed unchanged; pass --generate-service as well to regenerate
it explicitly. To enable startup at boot without starting the service immediately, use
sudo gt cron --install-service --no-start (or the equivalent vendor/bin/cron command). Reinstalling
the same symlink is supported; an existing file or link to another service is
rejected. Project basenames must contain only letters, numbers, dots, underscores
or hyphens. Keep the project and service file at stable paths. On a shared host,
project basenames must be unique. Generation and installation can also be combined
with --generate-service --install-service.
The service runs cron --watch in the foreground and restarts after exits. To
inspect or manage it (substitute your project's service name):
systemctl status www.php.gt-cron.service
journalctl -u www.php.gt-cron.service -f
sudo systemctl restart www.php.gt-cron.service
sudo systemctl disable --now www.php.gt-cron.serviceRestart after deployments to load changed schedules, configuration and PHP code.
For removal, disable/stop it first, remove its symlink from /etc/systemd/system,
and run sudo systemctl daemon-reload. The service does not add job timeouts,
missed-run replay, or graceful job completion on shutdown.