file – Magento 2 Cron.php-ThrowExceptions

Exception or error:

We had Magento 1 and a provider where we just typed the path of the cron.php file for a cronjob.
Example: anyname.com/cron.php

Now Magento 2 ist out and I found out that the cron.php file is now in /pub or /update folder. So I typed anyname.com/update/cron.php or anyname.com/pub/cron.php with .htaccess enabled :

 ## Deny access  to cron.php
#    <Files cron.php>
#       order allow,deny
#      deny from all
#   </Files>

Trying to do the cronjob this comes out:

/vendor/magento/module-cron/Observer/ProcessCronQueueObserver.php:173 Stack 
trace: #0 
/vendor/magento/framework/Event/Invoker/InvokerDefault.php(73): Magento\Cron\Observer\ProcessCronQueueObserver->execute(Object(Magento\Framework\Event\Observer)) #1 
/vendor/magento/framework/Event/Invoker/InvokerDefault.php(61): Magento\Framework\Event\Invoker\InvokerDefault->_callObserverMethod(Object(Magento\Cron\Observer\ProcessCronQueueObserver), Object(Magento\Framework\Event\Observer)) #2 
/vendor/magento/framework/Event/Manager.php(66): Magento\Framework\Event\Invoker\InvokerDefault->dispatch(Array, Object(Magento\Framework\Event\Observer)) #3 
/var/generation/Magento/Framework/Event/Manager/Proxy.php(95): Magento\Framework\Event\Manager->dispatch('default', Array) #4 
/vendor/magento/module-cron/Observer/ProcessCronQueueObserver.php on line 173
How to solve:

To execute CRON job in Magento 2, Magento 2 is providing CLI for that,
You have to set command from Magento 2 root directory to Start all the Magento default Cron

php bin/magento cron:run

0 0 * * * /usr/bin/php /var/www/html/magento_root/php bin/magento cron:run >/dev/null 2>&1

Please refer Magento 2 documentation for that.
Magento 2 CRON DevDocs

Answer:

To run cronjobs in magento 2 you should do:

This will setting up the cron in the crontab

bin/magento cron:install

Clean cache

bin/magento cache:flush

And then run the cron with the specific group

bin/magento cron:run --group="default"

Answer:

First to create any cron job in magento 2, you need to create crontab.xml file under etc folder.
After creating xml file in that file you need to mention your class name, time and function which you want to get execute at specific time.
group_name is user choice, you can use existing groups or you can create your own.

example

<config>
    <group id="<group_name>">
        <job name="<job_name>" instance="<classpath>" method="<method>">
            <schedule><time></schedule>
        </job>
    </group>
</config>

Answer:

Try this in cli: php bin/magento cron:run

Answer:

Your problem is that you are not reading documentation. In m2 you should execute cron via cli which is bin/magento cron:run.

Leave a Reply

Your email address will not be published. Required fields are marked *