0

I have made one script (addproducts.php) in my Magento root folder for adding products programmatically. For now, I am hitting this script in URL as localhost/addproducts.php. What should I do to execute this script through cron job. How can I set this script to run at regular time interval?

1
  • You can create Magento 2 module, then create Cron method and set that on crontab. Or you can directly set your script to cron through cpanel (crons) or if you have shell access then run crontab -e then you will get an editor where you can add your file as well. – Sukumar Gorai Feb 5 '20 at 12:45
0

There are 2 ways to execute that script.

First Method: Set cron job in server cPanel. You can follow below link to do this.

https://manage.accuwebhosting.com/knowledgebase/3043/How-to-set-the-cron-job-to-run-a-PHP-script-in-cPanel.html

Second Method: Create custom module to set cron job and execute your script. check below link for your help.

http://blog.chapagain.com.np/magento-2-creating-running-cron-in-custom-module/

Note: second method is highly recommended.

0

You can do this by using server hosting cPanel 'Add cron job' feature by specifying script file url and time of execution.

Also you can do this by creating a cron job using a module. For reference follow this link https://www.mageplaza.com/devdocs/magento-2-create-cron-job/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.