'How to Run an External Script in CI4 Controller

So, I have a Controller with an update script. Within the update script, if certain criteria is met, I want it to initiate the run script (also seen within same Controller).

Shop Controller:

    public function update()
    {
        $model = new ShopModel();
        return redirect()
            ->to('/shop/run');
    }
    public function run()
    {
        $model = new ShopModel();
        
        /^ Lots of code... */

    }

My first thought was to use redirect - which works great - if I physically run the script myself. However, the update script is initiated by a cron job - which I'm assuming can't handle the redirect element, as I get the following status: "Failed (HTTP error) 307 Temporary Redirect"

I know some will ask why I don't just put the contents of the run script within the update script... but as the run script also needs to be accessed separately - it makes more sense to include or require it within the update script, to save repeating a lot of hefty run code twice.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source