1

I have created a logic that look seems fine if I run that via controller file. But I am getting an error while running via cron (checked via log file), using magento2 cron process.

ModuleName/Cron/Myfile.php

Is there any way that I can run this file directly via browser to debug the things?

Please reply ASAP!

Amrit Pal Singh
  • 1,616
  • 1
  • 15
  • 35
Atul
  • 915
  • 2
  • 15
  • 34

1 Answers1

0

To run a php file in a browser from your module, you need to temporarily disable the .htaccess file in your app folder.

For example, rename it to .htaccess2.

Then you can browse the file in your browser like this:

http://domain.com/app/code/{vendor}/{module}/Cron/Yourfile.php

Just don't forget to return the .htaccess file back to normal after debugging.

EDIT

You can test functions by calling your file through browser like this: http://domain.com/path/to/cron/file/?function=testFunction

And in your cron php file, you can make a switch statement to call your functions like this:

switch($_GET['function']) {
    case 'testFunction':
        testFunction();
}

function testFunction() {
    echo 'test';
    // your cron logic
}

... //other functions

Although for debugging purposes, maybe you could use Magento's log functions to debug your problem.

See this question for more info: Magento 2: Replacement for Mage::log method?.

Lez
  • 2,907
  • 2
  • 23
  • 51