Here's the problem... I have 3 versions of PHP installed (each requires a different path to the PHP executable) and need to make sure that the same version of PHP runs cron as is used for the Apache user since I have many domain running different PHP versions. BUT I don't know how to convert these three cron lines to use wget (or even curl if that's better) instead of php?
* * * * * /opt/rh/rh-php56/root/usr/bin/php -c /home/example/etc/php.ini /home/example/public_html/bin/magento cron:run * * * * * /opt/rh/rh-php56/root/usr/bin/php -c /home/example/etc/php.ini /home/example/public_html/update/cron.php * * * * * /opt/rh/rh-php56/root/usr/bin/php -c /home/example/etc/php.ini /home/example/public_html/bin/magento setup:cron:run
Here's as close as I can get to guessing what to do... the middle line seems like it should work but doesn't and I have no idea what to use for the others.
* * * * * wget -O /dev/null -q http://www.example.com/???? > /dev/null * * * * * wget -O /dev/null -q http://www.example.com/update/cron.php > /dev/null * * * * * wget -O /dev/null -q http://www.example.com/???? > /dev/null
Is it even possible now with Magento 2 to use wget/curl to do the cron job for use cases like mine?
Solved! Go to Solution.
I think the answer to the question is straightforward - no, you cannot use wget instead of php in cron in Magento 2. And we are not likely to add this by default due to security ramifications.
If you really wanted to do wget, I am sure you could create a new REST end point or PHP page that invokes the same code as what bin/magento calls. The question is how to stop unwanted people triggering cron runs you did not want to happen. E.g. block the URL from external access? So I don't think it would be hard for you to set up yourself if you really wanted to do it this way.
My best short term advice is to have a shell script with all the settings in it, and get cron to run that. Sure, you have to work out the settings each web server users - but only once. Then you can save it in a file on disk.
Disclaimer/reminder - I can talk strategic direction - some of the low level technical details I guess at. Looking at https://github.com/magento/magento2/blob/077584c99ebb8007cad176c3b9a0144a05c259cd/app/code/Magento/C... it does not seem to be just a CURL command on the inside - it runs real code.
I do not recall there being a URL to trigger cron jobs. I cannot find an area name called "cron" for example. It could get funky with security, having an externally accessible URL that triggers the running of cron jobs would be bad.
Bottom line - I think you have to do something like you are doing, or have a shell script per installation. (As it happens, I was talking about this earlier today. Could we get the exact version of PHP built into the bin/magento script. The problem is if you did this, every time we patch the framework we would lose the local changes. In hindsite perhaps we should have made bin/magento a pure shell script and kept the PHP script in a separate file. Then we could look for a local configuration file to identify which PHP version to run. We are still thinking about this one.)
Thanks for your openness about your discussions!!!! This is amazing to have an open source community working like it should... not speaking to a black box! Would love to hear feedback if you guys decide to tackle this or if you or someone else thinks of a possible solution.
I also asked this question on StackExchange so am cross-referencing in case a solution pops up there. This problem is still not resolved.
I think the answer to the question is straightforward - no, you cannot use wget instead of php in cron in Magento 2. And we are not likely to add this by default due to security ramifications.
If you really wanted to do wget, I am sure you could create a new REST end point or PHP page that invokes the same code as what bin/magento calls. The question is how to stop unwanted people triggering cron runs you did not want to happen. E.g. block the URL from external access? So I don't think it would be hard for you to set up yourself if you really wanted to do it this way.
My best short term advice is to have a shell script with all the settings in it, and get cron to run that. Sure, you have to work out the settings each web server users - but only once. Then you can save it in a file on disk.
Thank you for your feedback Allen I will use the typical crontab methods then.