Post by d.andrian » Thu Dec 08, 2022 10:31 pm

Hello everyone,
I have been developing a custom module that I need to run through a cron job. When the cron job runs I get the following error

Code: Select all

Stack trace:
#0 {main}
  thrown in /home/Mywebsite/public_html/catalog/controller/extension/module/my_module.php on line 2
[08-Dec-2022 15:42:02 Europe/Athens] PHP Fatal error:  Uncaught Error: Class 'Controller' not found in /home/Mywebsite/public_html/catalog/controller/extension/module/my_module.php:2
my custom controller looks like this:

Code: Select all

<?php
class ControllerExtensionModuleMyModule extends Controller {	
	public function index() {
		file_put_contents("mylog.log","do something here" . "\n",FILE_APPEND);
	}
}
I tried running the cron from a command like the following:

Code: Select all

curl https://www.mywebsite.com/index.php?route=extension/module/my_module
but that doesn't work either, even though if I try the same URL from the browser it works just fine.

Thanks in advance for any ideas.

Newbie

Posts

Joined
Thu Dec 08, 2022 10:16 pm

Post by ADD Creative » Fri Dec 09, 2022 1:21 am

d.andrian wrote:
Thu Dec 08, 2022 10:31 pm
I tried running the cron from a command like the following:

Code: Select all

curl https://www.mywebsite.com/index.php?route=extension/module/my_module
but that doesn't work either, even though if I try the same URL from the browser it works just fine.
In what way does the above curl command not work? If it works in the browser in should work with curl.

It's also helpful to post your OpenCart and PHP version.

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by Majnoon » Fri Dec 09, 2022 1:42 am

class ControllerExtensionModuleMyModule extends Controller

Code: Select all

Controller | Extension | Module | My |Module

-Controller  = folder
-Extension  = folder
-Module = folder
-My     = folder
-Module = php file
So in the Controller folder you need to create a folder extension and inside of folder module and inside of folder my and inside of the folder is the Module file.

Also check your chmod permissions

Active Member

Posts

Joined
Fri Feb 05, 2021 8:29 pm

Post by d.andrian » Fri Dec 09, 2022 4:52 am

ADD Creative wrote:
Fri Dec 09, 2022 1:21 am
d.andrian wrote:
Thu Dec 08, 2022 10:31 pm
I tried running the cron from a command like the following:

Code: Select all

curl https://www.mywebsite.com/index.php?route=extension/module/my_module
but that doesn't work either, even though if I try the same URL from the browser it works just fine.
In what way does the above curl command not work? If it works in the browser in should work with curl.

It's also helpful to post your OpenCart and PHP version.
What I meant was that nothing is written to the log file when the cron job is executed but if I visit that URL from the browser it will write to the log file.
Forgot to mention the OC version is 3.0.3.7 and the PHP version is 7.3

Newbie

Posts

Joined
Thu Dec 08, 2022 10:16 pm

Post by d.andrian » Fri Dec 09, 2022 4:59 am

Majnoon wrote:
Fri Dec 09, 2022 1:42 am
class ControllerExtensionModuleMyModule extends Controller

Code: Select all

Controller | Extension | Module | My |Module

-Controller  = folder
-Extension  = folder
-Module = folder
-My     = folder
-Module = php file
So in the Controller folder you need to create a folder extension and inside of folder module and inside of folder my and inside of the folder is the Module file.

Also check your chmod permissions
While I understand what you are saying, I have many modules that work with this naming scheme. I think it's down to the "_" in the file name.
The file's permissions are 0644 just like the rest of the files in the controller.

Newbie

Posts

Joined
Thu Dec 08, 2022 10:16 pm

Post by JNeuhoff » Fri Dec 09, 2022 5:01 am

You should use the following folder structure:

catalog/controller/extension/module/my_module.php

and not:

catalog/controller/Extension/Module/My/Module.php

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member
Online

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by ADD Creative » Fri Dec 09, 2022 6:11 pm

d.andrian wrote:
Fri Dec 09, 2022 4:52 am
What I meant was that nothing is written to the log file when the cron job is executed but if I visit that URL from the browser it will write to the log file.
Forgot to mention the OC version is 3.0.3.7 and the PHP version is 7.3
If you are not getting any error and it's just that nothing is happening. It probably an issue with your curl cron job. Check your web access log to see if it's creating an entry. Could be the cron in not working or your curl path is wrong.

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by paulfeakins » Fri Dec 09, 2022 7:25 pm

d.andrian wrote:
Thu Dec 08, 2022 10:31 pm
I tried running the cron from a command like the following:

Code: Select all

curl https://www.mywebsite.com/index.php?route=extension/module/my_module
but that doesn't work either, even though if I try the same URL from the browser it works just fine.
That makes no sense, if it works in the browser it really should work from curl.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Guru Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by d.andrian » Fri Dec 09, 2022 7:37 pm

paulfeakins wrote:
Fri Dec 09, 2022 7:25 pm
d.andrian wrote:
Thu Dec 08, 2022 10:31 pm
I tried running the cron from a command like the following:

Code: Select all

curl https://www.mywebsite.com/index.php?route=extension/module/my_module
but that doesn't work either, even though if I try the same URL from the browser it works just fine.
That makes no sense, if it works in the browser it really should work from curl.
To make things stranger I copied the module from website 1 to website 2 and ran a curl cron job from website 1 to the module on website 2 and everything worked as it should. But when I tried to do the same from website 2 to website 1, again nothing happened. I'm baffled.

Newbie

Posts

Joined
Thu Dec 08, 2022 10:16 pm

Post by paulfeakins » Fri Dec 09, 2022 8:16 pm

d.andrian wrote:
Fri Dec 09, 2022 7:37 pm
To make things stranger I copied the module from website 1 to website 2 and ran a curl cron job from website 1 to the module on website 2 and everything worked as it should. But when I tried to do the same from website 2 to website 1, again nothing happened. I'm baffled.
Probably some sort of server security like mod_security - it usually is with this kind of weird problem.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Guru Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom
Who is online

Users browsing this forum: Baidu [Spider], jagall, Semrush [Bot], SohBH and 258 guests