Answers.Body: <p>Site key should be defined in <code>civicrm.settings.php</code>, not <code>settings.php</code>, which isn't necessarily bootstrapped when cron is run.</p>
  
  <p>If that was mis-stated in your question (likely, since you're using WordPress), you can try to troubleshoot this by debugging.</p>
  
  <ul>
  <li>Find your <a href="https://civicrm.stackexchange.com/questions/15931/where-are-the-configandlog-and-templates-c-directories">CiviCRM log</a> and your <a href="https://civicrm.stackexchange.com/questions/16610/where-is-civicrm-installed">CiviCRM root</a>.</li>
  <li><p>In your CiviCRM root, find the file <code>CRM/Utils/System.php</code>.</p></li>
  <li><p>Find this section (around line 553):</p>
  
  <pre><code>if ($key !== $siteKey) {
    return self::authenticateAbort(
      "ERROR: Invalid key value sent. " . $docAdd . "\n",
      $abort
    );   
  }  
  </code></pre></li>
  <li><p>Add two debugging lines so that section now looks like:</p>
  
  <pre><code>if ($key !== $siteKey) {
    CRM_Core_Error::debug_var('key', $key);
    CRM_Core_Error::debug_var('siteKey', $siteKey);
    return self::authenticateAbort(
      "ERROR: Invalid key value sent. " . $docAdd . "\n",
      $abort
    );   
  }  
  </code></pre></li>
  <li><p>Run your cron job again, get the same error.</p></li>
  <li><p>Check the CiviCRM log.  At or very near the bottom of the log file, you should see lines that look like:</p>
  
  <pre><code>$key = 456;
  $siteKey = 456;
  </code></pre></li>
  </ul>
  
  <p>...except I'm guessing that one of them looks slightly wrong!  Use that information to either fix this problem and/or update this question with more info.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-12T02:13:14.890Z
Answers.Text: Don't forget to remove those last two lines when you're done!
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-12T19:46:18.443Z
Answers.Text: Yes, sorry, my laziness 'CIVICRM_SITE_KEY', '456' is defined in civicrm.settings.php
Answers.UserDisplayName: John Bradford
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-12T19:49:50.270Z
Answers.Text: Weirdly error files are being saved in the domain home so I've public_html & subdomains folders .bash_history .bashrc .htaccess and then a cron.php?name=JohnB&pass=123&key=456.28 - the 28 referring to the other 27 copies as I left cron running to see what would happen :-) they all have the same content:  ERROR: Invalid key value sent. More info at:http://wiki.civicrm.org/confluence/display/CRMDOC/Managing+Scheduled+Jobs
Answers.UserDisplayName: John Bradford
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-12T19:56:14.363Z
Answers.Text: CiviCRM.5ea62a755e1d78acd0439277.log (my latest log file) doesn't appear to have those 2 lines anywhere: it's failing and generating a bucket load of error msg's but mostly around shortcodes (and the time stamps don't match the cron trigger) so something else needs looking at. :(
Answers.UserDisplayName: John Bradford
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-12T20:13:59.920Z
Answers.Text: ok may have just spotted the deliberate error - just above the if ($key !== $siteKey) { is a line :     $siteKey = defined('CIVICRM_SITE_KEY') ? CIVICRM_SITE_KEY : NULL; will try changing NULL to the value in civicrm.setting.php
Answers.UserDisplayName: John Bradford
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-12T20:25:29.703Z
Answers.Text: ok - changing NULL to 456 or '456' doesn't change anything - deleting the ? CIVICRM_SITE_KEY : NULL fails the whole siteKey check and it's now saying I need a siteKey of more than 7 characters.
Answers.UserDisplayName: John Bradford
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-13T05:27:24.700Z
Answers.Text: Right - I edited the system error msg to include the two $key & $siteKey values - $siteKey was the old value (not the current civicrm.settings.php value) - anyway I've updated cron to use the old value and that seems to work. Many thanks for the pointers above @jon-g
Answers.UserDisplayName: John Bradford
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-13T05:35:12.500Z
Answers.Text: and Civicrm is reporting cron running! Still have a "Error loading module file (). Please restore the file or disable the module." to sort out but getting there. Many thanks.
Answers.UserDisplayName: John Bradford
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-13T11:50:12.080Z
Answers.Text: @JohnBradford Glad that my tips fixed the problem!  Of note though - the SITEKEY is never stored in the database, only in files (usually `civicrm.settings.php`).  Since you're seeing the old site key and not the current value, I'm guessing that someone stuck a SITEKEY somewhere they shouldn't have.  I would consider doing a text search for the old site key in your entire WordPress filesystem to figure out where and why.
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-15T18:48:22.093Z
Answers.Text: I did a grep -r "SITE_KEY" I think it may have been a caching issue - no errant SITE_KEY def statements - cron still working.
Answers.UserDisplayName: John Bradford
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-10T17:22:40.537Z
Answers.Text: I am having this same issue, but Like @JohnBradford, I cannot get the two lines to show up in my log.
Answers.UserDisplayName: Tiffany Carra
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-12T02:12:48.800Z
Answers.LastActivityDate: 2017-01-12T02:12:48.800Z
Answers.LastEditDate: 2017-04-13T12:53:13.167Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Body: <p>Really getting frustrated trying to get cron to work.</p>
  
  <p>WP 4.7 / CiviCRM 4.7.14</p>
  
  <p>using via ssh:</p>
  
  <p>/usr/bin/wget '<a href="https://hbb.org.uk/wp-content/plugins/civicrm/civicrm/bin/cron.php?name=JohnB&amp;pass=123&amp;key=456" rel="nofollow noreferrer">https://hbb.org.uk/wp-content/plugins/civicrm/civicrm/bin/cron.php?name=JohnB&amp;pass=123&amp;key=456</a>'</p>
  
  <p>Generates the error.</p>
  
  <p>my settings.php has:</p>
  
  <p>if (!defined('CIVICRM_SITE_KEY')) {
    define( 'CIVICRM_SITE_KEY', '456');
  }</p>
  
  <p>Where the two keys are identical. There are no special characters, it's a 20 char string, I've re-entered a new string into both settings.php and the wget. Each time generates a new error log file with the msg.</p>
  
  <p>When I enter the url into Chrome I get "Invalid key". Yet they're identical in the wget and settings.php.</p>
  
  <p>Is there some super-sekret settings file somewhere?</p>
  
Tags: <wordpress><cron>
Title: Cron - Invalid key value sent
ThreadText: # Cron - Invalid key value sent
  
  (Asked by: username_0 on 2017-01-11)
  
  Really getting frustrated trying to get cron to work.
  
  WP 4.7 / CiviCRM 4.7.14
  
  using via ssh:
  
  /usr/bin/wget '<https://hbb.org.uk/wp-content/plugins/civicrm/civicrm/bin/cron.php?name=JohnB&pass=123&key=456>'
  
  Generates the error.
  
  my settings.php has:
  
  if (!defined('CIVICRM\_SITE\_KEY')) {
  define( 'CIVICRM\_SITE\_KEY', '456');
  }
  
  Where the two keys are identical. There are no special characters, it's a 20 char string, I've re-entered a new string into both settings.php and the wget. Each time generates a new error log file with the msg.
  
  When I enter the url into Chrome I get "Invalid key". Yet they're identical in the wget and settings.php.
  
  Is there some super-sekret settings file somewhere?
  
  **Tags:** wordpress, cron
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-01-12. Score: 0 | Accepted answer
  
  Site key should be defined in `civicrm.settings.php`, not `settings.php`, which isn't necessarily bootstrapped when cron is run.
  
  If that was mis-stated in your question (likely, since you're using WordPress), you can try to troubleshoot this by debugging.
  
  * Find your [CiviCRM log](https://civicrm.stackexchange.com/questions/15931/where-are-the-configandlog-and-templates-c-directories) and your [CiviCRM root](https://civicrm.stackexchange.com/questions/16610/where-is-civicrm-installed).
  * In your CiviCRM root, find the file `CRM/Utils/System.php`.
  * Find this section (around line 553):
  
    ```
    if ($key !== $siteKey) {
      return self::authenticateAbort(
        "ERROR: Invalid key value sent. " . $docAdd . "\n",
        $abort
      );   
    }  
  
    ```
  * Add two debugging lines so that section now looks like:
  
    ```
    if ($key !== $siteKey) {
      CRM_Core_Error::debug_var('key', $key);
      CRM_Core_Error::debug_var('siteKey', $siteKey);
      return self::authenticateAbort(
        "ERROR: Invalid key value sent. " . $docAdd . "\n",
        $abort
      );   
    }  
  
    ```
  * Run your cron job again, get the same error.
  * Check the CiviCRM log. At or very near the bottom of the log file, you should see lines that look like:
  
    ```
    $key = 456;
    $siteKey = 456;
  
    ```
  
  ...except I'm guessing that one of them looks slightly wrong! Use that information to either fix this problem and/or update this question with more info.
  
  > **Comments:**
  > **username_1**: Don't forget to remove those last two lines when you're done!  
  > **username_0**: Yes, sorry, my laziness 'CIVICRM_SITE_KEY', '456' is defined in civicrm.settings.php  
  > **username_0**: Weirdly error files are being saved in the domain home so I've public_html & subdomains folders .bash_history .bashrc .htaccess and then a cron.php?name=JohnB&pass=123&key=456.28 - the 28 referring to the other 27 copies as I left cron running to see what would happen :-) they all have the same content:  ERROR: Invalid key value sent. More info at:http://wiki.civicrm.org/confluence/display/CRMDOC/Managing+Scheduled+Jobs  
  > **username_0**: CiviCRM.5ea62a755e1d78acd0439277.log (my latest log file) doesn't appear to have those 2 lines anywhere: it's failing and generating a bucket load of error msg's but mostly around shortcodes (and the time stamps don't match the cron trigger) so something else needs looking at. :(  
  > **username_0**: ok may have just spotted the deliberate error - just above the if ($key !== $siteKey) { is a line :     $siteKey = defined('CIVICRM_SITE_KEY') ? CIVICRM_SITE_KEY : NULL; will try changing NULL to the value in civicrm.setting.php  
  > **username_0**: ok - changing NULL to 456 or '456' doesn't change anything - deleting the ? CIVICRM_SITE_KEY : NULL fails the whole siteKey check and it's now saying I need a siteKey of more than 7 characters.  
  > **username_0**: Right - I edited the system error msg to include the two $key & $siteKey values - $siteKey was the old value (not the current civicrm.settings.php value) - anyway I've updated cron to use the old value and that seems to work. Many thanks for the pointers above @jon-g  
  > **username_0**: and Civicrm is reporting cron running! Still have a "Error loading module file (). Please restore the file or disable the module." to sort out but getting there. Many thanks.  
  > **username_1**: @username_0 Glad that my tips fixed the problem!  Of note though - the SITEKEY is never stored in the database, only in files (usually `civicrm.settings.php`).  Since you're seeing the old site key and not the current value, I'm guessing that someone stuck a SITEKEY somewhere they shouldn't have.  I would consider doing a text search for the old site key in your entire WordPress filesystem to figure out where and why.  
  > **username_0**: I did a grep -r "SITE_KEY" I think it may have been a caching issue - no errant SITE_KEY def statements - cron still working.  
  > **username_2**: I am having this same issue, but Like @username_0, I cannot get the two lines to show up in my log.  
  
  ---
  
  