Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#49327 closed enhancement (worksforme)

Add a function that identifies whether WordPress is doing a cron

Reported by: pikamander2's profile pikamander2 Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.8
Component: Cron API Keywords:
Focuses: Cc:


Ideally, there would be three possible return values:

  1. A value that indicates that no cron is being performed
  1. A value that indicates that a WP_CRON is being performed
  1. A value that indicates that a cron is being performed via the CLI

This would mostly be helpful for logging purposes. For example, some hosts use a setup in which crons are run by a different user than normal (apache, root, www-data, etc), which can affect things like your environment variables and file permissions.

Even though it's not strictly necessary, it would be helpful to have it as an option.

Change History (1)

#1 @Clorith
4 years ago

  • Component changed from General to Cron API
  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed
  • Version set to 4.8


There's actually a way to do this already, either with the function wp_doing_cron() (recommended), or looking for the constant DOING_CRON and seeing if it's true.

As for if it's being performed via CLI, that can be done by looking at the PHP native function php_sapi_name(), you'll see cli as the output if it's on the command line.

Since these options already exist, I'm going to mark this ticket as closed, but if you feel there's something that could be done better, please do follow up in here, as it's just a task-management status, and conversations can still continue.

Note: See TracTickets for help on using tickets.