Cron job returns "Undefined index: REQUEST_METHOD" |
Hi,
I'm attempting to run a cron job using CodeIgniter 3.1.8. The cron job works fine locally from the Windows command line, but when I run it on a Linux server as a CPanel cron, I get this in the output (among various other session related warnings): <h4>A PHP Error was encountered</h4> <p>Severity: Notice</p> <p>Message: Undefined index: REQUEST_METHOD</p> <p>Filename: core/Security.php</p> <p>Line Number: 211</p> Would be grateful for any help...
anturom,
You have to give us more information. Can we see the code in the cron job? Are you running the same version of PHP? If one system is Windows and the other is Linux, what is the difference that could be causing the problem?
Sounds like CSRF protection to me. Depending on how your accessing the script for the cronjob.
CSRF protection is enabled. Windows machine is running PHP 7.1.17. Linux server is running PHP 7.1.27. My CPanel cronjob has the form:
Code: /usr/bin/php -f /home/<directory>/<directory>/index.php cronjobs statistics My relevant controller code: Code: class Cronjobs extends CI_Controller
03-20-2019, 11:36 AM
(This post was last modified: 03-20-2019, 11:48 AM by anturom. Edit Reason: corrected URL )
@php_rocs,
Yes, to be more accurate, on Windows I can run this job successfully from the command line manually (not actually as a cron), like this: Code: php index.php cronjobs statistics From the log on the Linux server where I get the problem I can now see that it falls back for some reason to the default controller, namely: Code: DEBUG - 2019-03-20 19:32:01 --> UTF-8 Support Enabled I've double checked of course that the path to index.php is correct in my cron job. Maybe it's worth pointing out that the server directory where index.php lives is not public_html, but a directory parallel to public_html. Also, the directory name contains dots, like "my.subdomain.com", if that matters. So basically the structure is: Code: dir The route http://sandbox.mydomain.com/cronjobs/statistics correctly returns 401 when accessed directly from the browser. I've also tried disabling CSRF protection completely just to be able to narrow down the issue, but that didn't help...
The problem has now been solved, by calling PHP with
Code: /usr/bin/php-cli instead of just Code: /usr/bin/php Thank you everyone for interest in this issue! |
Welcome Guest, Not a member yet? Register Sign In |