Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: cli not working with cron #4699

Closed
pixobit opened this issue May 17, 2021 · 4 comments · Fixed by #4725
Closed

Bug: cli not working with cron #4699

pixobit opened this issue May 17, 2021 · 4 comments · Fixed by #4725
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@pixobit
Copy link
Contributor

pixobit commented May 17, 2021

Direction
We use github issues to track bugs, not for support.
If you have a support question, or a feature request, raise these as threads on our
forum.

Describe the bug
I was trying to run CI4 through cli, and it didn't seem to be working... So after a long debugging session, I've found out that CI4 wasn't recognizing it as a cli execution, and the routing was failing because of this. The reason was, that if CI4 is called by crontab, the PHP_SAPI constant will return 'cgi-fcgi' instead of 'cli' which is checked against in Common.php fn is_cli()

CodeIgniter 4 version
4.1.1

Affected module(s)
Which package or class is the bug in, if known.

Expected behavior, and steps to reproduce if appropriate
Expected to work the same way, as when I run it from cli

Context

  • OS: CentOS 7
  • Web server Apache 2
  • PHP version 7.4
@pixobit pixobit added the bug Verified issues on the current code behavior or pull requests that will fix them label May 17, 2021
@paulbalandan
Copy link
Member

When running inside the cron, can you check the value of the TERM env variable?

var_dump(getenv('TERM'));

@pixobit
Copy link
Contributor Author

pixobit commented May 18, 2021

Will check later today when I get a bit of free time

@pixobit
Copy link
Contributor Author

pixobit commented May 20, 2021

it returns "bool(false)"

@paulbalandan
Copy link
Member

Last checks to see if CGI can be safely regarded as CLI.

var_dump(! isset($_SERVER['REMOTE_ADDR']));
var_dump(! isset($_SERVER['HTTP_USER_AGENT']));
var_dump(count($_SERVER['argv']) > 0);
var_dump(! isset($_SERVER['REQUEST_METHOD']));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants