Welcome Guest, Not a member yet? Register   Sign In
Accessing Controller with CRON
#6

(11-18-2021, 04:06 PM)kenjis Wrote: Check your letter case of filename, folder name and classname.
Tools.php
class Tools

Thank you all so much for you help.

To ensure I have my paths, folder and file names correct, even the correct case, I have run the followingb tests.

I created a very simple php file: test.php
PHP Code:
<?php

echo "I am at /home/my-app/app/Controllers/test.php"

I updated my Cron command to

/usr/bin/php /home/my-app/app/Controllers/test.php >> /home/my-app/app/Controllers/logfile.php

As expected this worked well, the cron job run correctly output =I am at /home/my-app/app/Controllers/test.php

Next I amended test.php using the structure of a file that works in the application.
PHP Code:
<?php namespace App\Controllers;

use 
CodeIgniter\Controller;
use 
CodeIgniter\Database\Query;
use 
App\Controllers\BaseController;

class 
test extends BaseController {
 
     public function index() {
     echo "I am at /home/my-app/app/Controllers/test.php";
     die();
     }


I left my Cron command unchanged

/usr/bin/php /home/my-app/app/Controllers/test.php >> /home/my-app/app/Controllers/logfile.php

As expected this worked well, the cron job run correctly output = 500 Internal Server Error
The Cron found the file, but as expected the file did not execute correctly

Then I changed my Cron command to (as described in the Ci4 user manual
/usr/bin/php /home/my-app/mydonain.co.uk/index.php test >> /home/my-app/app/Controllers/logfile.php

This did NOT work well, the cron job run could not find the file and output = Status: 404 Not Found

I also tried the following commands
/usr/bin/php /home/my-app/mydonain.co.uk/index.php Controllers test >> /home/my-app/app/Controllers/logfile.php
/usr/bin/php /home/my-app/mydonain.co.uk/index.php app Controllers test >> /home/my-app/app/Controllers/logfile.php
/usr/bin/php /home/my-app/mydonain.co.uk/index.php my-app app Controllers test >> /home/my-app/app/Controllers/logfile.php
/usr/bin/php /home/my-app/mydonain.co.uk/index.php home my-app app Controllers test >> /home/my-app/app/Controllers/logfile.php
/usr/bin/php /home/my-app/mydonain.co.uk/index.php /home my-app app Controllers test >> /home/my-app/app/Controllers/logfile.php

All failed with output = Status: 404 Not Found

So as per the manual, I set up a route (in common with all the other routes in my application)
PHP Code:
$routes->add('testing''test::index'); 


This time my Cron command read
/usr/bin/php /home/my-app/mydonain.co.uk/index.php testing index >> /home/my-app/app/Controllers/logfile.php

Again this failed with output = Status: 404 Not Found

It would appear that the Cron is expecting the target file to be in the /home/my-app/mydonain.co.uk/ folder ???

Hmmmmmmm.....

To use a sporting parlance, I feel "snookered".
Reply


Messages In This Thread
Accessing Controller with CRON - by 68thorby68 - 11-17-2021, 10:37 AM
RE: Accessing Controller with CRON - by Secux - 11-17-2021, 02:20 PM
RE: Accessing Controller with CRON - by kenjis - 11-17-2021, 10:18 PM
RE: Accessing Controller with CRON - by kenjis - 11-18-2021, 04:06 PM
RE: Accessing Controller with CRON - by 68thorby68 - 11-21-2021, 05:30 AM
RE: Accessing Controller with CRON - by kenjis - 11-21-2021, 05:41 AM



Theme © iAndrew 2016 - Forum software by © MyBB