You can force the script command line to use your first argument as a function to call, and then the arguments you need to pass to it. Arguments will appear in the variable of the magic array $argv.
$name_of_php_script = array_unshift($argv);
$callback = array_unshift($argv);
call_user_func_array($callback, $argv);
Obviously, you may need to make things more complicated for security or pass special values of some kind, but this does the basic logic that you describe in the question.
IMSoP source
share