CLI script template

Hi, my PHP Maker 2026 application needs to run CLI scripts, to execute a few database queries and send emails to the users.
In v2025 this would work, but fails in v2026 (even after updating the namespace):

<?php
namespace PHPMaker2025\demo2025;

use DI\ContainerBuilder;

// Autoload
require_once "vendor/autoload.php";

// Require files
require_once "src/constants.php";
require_once "src/config.php";
require_once "src/phpfn.php";
require_once "src/userfn.php";

$containerBuilder = new ContainerBuilder();
$containerBuilder->useAttributes(true);

// Add definitions
$containerBuilder->addDefinitions("src/definitions.php");

// Dispatch container build event
DispatchEvent(new ContainerBuildEvent($containerBuilder), ContainerBuildEvent::NAME);

// Build PHP-DI container instance
$container = $containerBuilder->build();

echo "<h3>Custom File without Include common files option</h3>";

$sql = "SELECT `Model` FROM `models`"; // define your SQL
$stmt = ExecuteQuery($sql); // execute the query
$value = ""; // initial value
if ($stmt->rowCount() > 0) { // check condition: if record count is greater than 0
    while ($row = $stmt->fetchAssociative()) { // loop
        $value .= $row["Model"] . "<br>"; // in case the result returns more than one record, display it and separated by line break
    } // end loop
    echo "Here is the Models list: <br>" . $value; // display the result
} else { // if there are no result
    echo "No record found."; // display the message
} // end of check condition

?>

What would be the proper CLI template for v2026? Thanks!

What did you meant by "CLI" in your case? How did you run your script?

If you meant you run your script in the browser by accessing the custom file direclty (e.g. http://yoursite/yourcustomfile.php), then you should use Controller_Action server event instead. Avoid standalone script, think your web application as an app, not a bunch of independent scripts.

I mean as in (PHP_SAPI == “cli”). I need to run a script via scheduled task on Windows or cron job on Linux. I appreciate your advice on best practices, but there’s no avoiding this need. Without it, I cannot update a client’s application built on v2025, so that will be most appreciated.

Then you should use Console Command for Symfony app.

You may use Custom File (Case 2) to create a command and move your core code to the __invoke() method and run it by CLI:

php bin/console app:your-command

Notes for the Custom File:

  1. The output folder should be src/Command,
  2. Note the namsepace in the Custom File, it should be like:
// src/Command/XxxCommand.php
namespace {ProjectNamespace}\Command;

use function {ProjectNamespace}\ExecuteQuery;

// Your code