CLI Documentation

The TikNix framework includes comprehensive CLI support for running controllers from the command line, perfect for cron jobs, background tasks, and administrative scripts.

CLI Command Reference

Basic Usage

php public/index.php [options]

Options

Option Description Example
--help Show help message php index.php --help
--control=NAME Controller name (required) --control=test
--method=NAME Method name (default: index) --method=cleanup
--member=ID Member ID to run as --member=1
--params=STRING URL-encoded parameters --params='id=5&type=pdf'
--json=JSON JSON parameters --json='{"key":"value"}'
--cron Cron mode (suppress output) --cron
--verbose Verbose output --verbose

Examples

Run a simple command

php public/index.php --control=test --method=hello

Run with parameters

php public/index.php --control=report --method=generate --params='type=daily&format=pdf'

Run as specific member

php public/index.php --member=1 --control=admin --method=cleanup

Cron job example

0 2 * * * /usr/bin/php /path/to/index.php --control=cleanup --method=daily --member=1 --cron

CLI Handler Architecture

The TikNix CLI system uses the CliHandler class to:

  • Parse command-line arguments
  • Set up the execution environment
  • Handle authentication (run as specific member)
  • Route to the appropriate controller/method
  • Manage output (verbose, cron mode, etc.)

Environment Variables

The CLI handler sets these environment variables:

REQUEST_URI    = /controller/method
REQUEST_METHOD = GET (default) or specified method
HTTP_HOST      = cli (for session handling)

Troubleshooting

Common Issues

Permission Denied

# Ensure the script is executable
chmod +x public/index.php

# Run with proper PHP binary
/usr/bin/php public/index.php --control=test

Class Not Found

Make sure the controller exists and follows naming conventions:

  • Controller file: controls/Test.php
  • Class name: class Test extends BaseControls\Control
  • Namespace: namespace app;

Database Connection Issues

CLI mode uses the same database configuration as web mode. Check:

  • Database credentials in conf/config.ini
  • Database server is accessible from CLI environment
  • PHP CLI has required database extensions

Debugging

# Use verbose mode for detailed output
php public/index.php --control=test --method=debug --verbose

# Check logs
tail -f log/app-*.log

# Test database connection
php -r "require 'bootstrap.php'; \$app = new app\Bootstrap('conf/config.ini');"

TikNix Framework v1.0 | PHP 8.3.24 | 2026